JDBC Null pointer Exception thrown

Posted by harigm on Stack Overflow See other posts from Stack Overflow or by harigm
Published on 2010-04-12T11:16:30Z Indexed on 2010/04/12 11:23 UTC
Read the original article Hit count: 578

Filed under:
|
|
|

Hi I'm getting nullpointerexception at rs.next() or rs.getString(1) it is really weird that sometimes rs.next() works fine and it throws nullpointerexception at rs.getString("PRODUCTCODE"),sometimes it throws npe at rs.getString("PRODDATE") i dont understand why rs.getString() thows npe while rs.next() works fine

Here is my code

{ 
ResultSet rs = null;
String query = "";
BarcodeBean bi = null;
try {
query = "SELECT * FROM TABLE(GET_BARCODEINFO('"barcode.trim()"'))";

statement = connection.createStatement();
Logger.getInstance().getLogger().logInfo(query);
rs = statement.executeQuery(query);

bi = new BarcodeBean();

if (rs == null){
if(rs.next()){

bi.setUrunKodu(rs.getString("PRODUCTCODE"));
bi.setImalatMakineKodu(rs.getString("PRODMACHINECODE")); 
bi.setOperatorSicilNo(rs.getString("OPERATORID")); 
bi.setImalatTarihi(rs.getString("PRODDATE")); 
bi.setImalatVardiyasi(rs.getString("PRODSHIFT"));
bi.setSeriNumarasi(rs.getString("SERIALNUMBER"));
bi.setSirtTarihi(rs.getString("SIRTTARIHI"));
}
}
} catch (SQLException e) {
e.printStackTrace();
throw e;
} catch (Exception e) {
e.printStackTrace();
} finally {

DatabaseUtility.close(rs);
DatabaseUtility.close(statement);

}
} 

© Stack Overflow or respective owner

Related posts about jdbc

Related posts about java