Re: NullPointerException error...
From: Roland (roland_at_phony.biz)
Date: 02/20/05
- Next message: Steve Horsley: "Re: NullPointerException error..."
- Previous message: Sebastian Scheid: "Re: eclipse and servlets"
- In reply to: Frances Del Rio: "Re: NullPointerException error..."
- Next in thread: Steve Horsley: "Re: NullPointerException error..."
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Sun, 20 Feb 2005 19:22:59 +0100
On 20-2-2005 17:55, Frances Del Rio wrote:
> Frances Del Rio wrote:
>
>> try {
>> String url = <url>;
>> Statement stmt; // no problem here...
>>
>> ResultSet rs; // get error says this var should be initialized..
>> // if I do
>> ResultSet rs = null; // get java.lang.NullPointerException error..
>>
>>
>> Class.forName("com.mysql.jdbc.Driver").newInstance();
>> con = DriverManager.getConnection(url);
>>
>> stmt = con.createStatement();
>> while (rs.next()) {
>> String themovies = rs.getString("title");
>> // out.print(themovies);
>> }
>
>
> had posted wrong code.. here it is again..
>
> try {
> String url = <url>;
> Statement stmt;
>
> ResultSet rs; // get error says this var should be initialized..
> // if I do
> ResultSet rs = null; // compiles fine, but get NullPointerException
> // when try to run.. (this is a servlet..)
> // (would love to know why all examples in this guy's book
> // are stand-alone's instead of either jsp's or servlets..
> // adapted from www.francesdelrio.com/java/oreillycode.html..)
>
>
> Class.forName("com.mysql.jdbc.Driver").newInstance();
>
> // ******* open connection ***********
> con = DriverManager.getConnection(url);
> String query = "select * from movies";
> stmt = con.createStatement();
>
> stmt.executeQuery(query);
^^^^
rs = stmt.executeQuery(query);
> while (rs.next()) {
> String themovies = rs.getString("title");
> // out.print(themovies); // don't know if this is right,
> // but can't find out before I solve
> // above-mentioned error..
> }
>
> hope this is not too muddled.. thank you very much.. Frances
>
>
>
The ResultSet never got assigned with the result of the query (hence, it
still was null, causing the NPE in the while test).
-- Regards, Roland de Ruiter ___ ___ /__/ w_/ /__/ / \ /_/ / \
- Next message: Steve Horsley: "Re: NullPointerException error..."
- Previous message: Sebastian Scheid: "Re: eclipse and servlets"
- In reply to: Frances Del Rio: "Re: NullPointerException error..."
- Next in thread: Steve Horsley: "Re: NullPointerException error..."
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|