Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Null pointer exception

 
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;
 
Author
Posts: 974
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.
 
Sheriff
Posts: 21972
106
Eclipse IDE Spring VI Editor Chrome Java Ubuntu 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.
 
author
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.
 
    Bookmark Topic Watch Topic
  • New Topic