Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Null pointer exception

 
Anand Karia
Ranch Hand
Posts: 156
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear All,

I am using Netbeans IDE and postgres as backend database.

I have a table naming bc_scan with columns (tokenno varchar, dtime timestamp, swapmode char(1)). I have entered timestamp in dtime field
When i am trying to get data on pgadmin then it shows data but when i am placing the query on my ide then it shows null pointer exception. Although it shows getFetchSize() = 1.

String Sql = select dtime from bc_scan where tokenno = '01' and swapmode = '02';
Statement st = ??? so on.......
ResultSet rs = st.executeQuery(sql);
It Shows error on any of these.

1. rs.getString(1);
2. rs.getDate(1);
3. rs.getTimeStamp(1);
4. rs.getString(1).toString;
 
Brian Cole
Author
Ranch Hand
Posts: 903
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Anand Karia:
String Sql = select dtime from bc_scan where tokenno = '01' and swapmode = '02';
Statement st = ??? so on.......
ResultSet rs = st.executeQuery(sql);
It Shows error on any of these.

1. rs.getString(1);
2. rs.getDate(1);
3. rs.getTimeStamp(1);
4. rs.getString(1).toString;


Do you ever call rs.next()?

btw, it probably would have made more sense to post your question to the JDBC forum, as it doesn't have any Swing/AWT/SWT/JFace content.
 
Rob Spoor
Sheriff
Pie
Posts: 20511
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Forgetting to call rs.next() should not result in an NPE but an SQLException instead.
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1.-3. cannot possibly throw a NPE, unless the JDBC driver has a bug (quite unlikely).

It would probably help if you showed us the true code and the stack trace.
 
Anand Karia
Ranch Hand
Posts: 156
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear All

First i would like to inform you that rs.next() is already written.
Finally when i change my jdbc driver from old one to new one then it show me correct result.

But this is really imazing that one form is getting result without any error from same old jdbc driver and another form is not. If i found any solution that why this problem has occur then i will definately post it here, if opssible.

Anyhow my this problem have been solved out through changing of jdbc driver.

Thank you all.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic