How do I keep proceeding

If there's a null in the table and when the resultset is returned.

And when we process the resultset, it throws a NullPointerException

like in the following piece of code.

pstmt=con.prepareStatement("SELECT * FROM product where p_id=?");

pstmt.setInt(1,id);

ResultSet rs=pstmt.executeQuery();

textfield.setText(rs.getString(1));

lets assume there's a table Products with a column that says description.

And it can be null.

The problem is that, it exits with a NullPointerException at that point.

What if I want to still keep processing the other data, even though a field is null. How do I do that?

[692 byte] By [ArcherKinga] at [2007-11-27 5:46:46]
# 1
u can keep ur statement which can be null in a condition checking for not null.like if(rs.getString(3) != null){...do ur code...}
Neelima.Sridhara at 2007-7-12 15:30:17 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 2
I actually tried that on java 1.3 and it didnt work. Let me try the same on java 1.6
ArcherKinga at 2007-7-12 15:30:17 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 3
looks like it works on my home computer with java 1.6No problems.Something must be wrong with java 1.3 (the system on which I learn java) :(Has anyone run into similar problems before?
ArcherKinga at 2007-7-12 15:30:17 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 4
That will work on any version of Java. You must have had a different bug. Quite probably you had a null resultset for some reason.
dcmintera at 2007-7-12 15:30:17 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...