error if retrieved values are null

Hello, i am trying to retrieve the value of a column which can be null but i get a very general message:java.sql.SQLException.

this is the code i use:

try

{

Class.forName ("sun.jdbc.odbc.JdbcOdbcDriver");

Connection con = DriverManager.getConnection( "jdbc:odbc:hospital","doctor", "doctor");

PreparedStatement pstmt = con.prepareStatement("SELECT aktinografia.ektimhsh FROM aktinografia WHERE aktinografia.aktin_code = ? ");

pstmt.setInt(1,g2);

ResultSet rset=pstmt.executeQuery();

while(rset.next())

{

str1= rset.getString("ektimhsh");

}

pstmt.close();

con.close();

}

catch(SQLException e)

{

out.print(e);

}

Please help!

Thanks in advance.

[797 byte] By [dados] at [2007-9-26 7:00:21]
# 1

In your catch block:

catch(SQLException e)

{

out.print(e);

e.printStackTrace() //add this line to get the stack trace

}

Run your app again and post the stack trace, that will help in determining the actual problem.

ashutosh at 2007-7-1 16:35:32 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 2
Try str1= rset.getString("aktinografia.ektimhsh");
DrClap at 2007-7-1 16:35:32 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 3
Couldn't you simply check for the null?str1=rset.getString("ektimhsh");if (rset.wasNull())str1="";
isjm at 2007-7-1 16:35:32 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 4
. . .if(rs!=null)while(rs.next()){. . .
Friz33 at 2007-7-1 16:35:32 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 5
String test = "";if (rs.getString("field1")!=null){test = rs.getString("field1"); }
zhenggf_sun at 2007-7-1 16:35:32 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 6

> if (rs.getString("field1")!=null)

> {

>

> test = rs.getString("field1");

>

> }

Just a small addition ,JDK docs ->

"For maximum portability, ResultSet columns within each row should be read in left-to-right order and each column should be read only once. "

kk77 at 2007-7-1 16:35:32 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...