Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

setting the null and getting null

 
ramchander yshetti
Ranch Hand
Posts: 97
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hai,
sorry, iam not clear about the answer

i created a table as

sno number(5)
sname varchar2(15)

PreparedStatement pst=con.prepareStatement("insert into mytab values(?,?)");
pst.setNull(1,Types.NULL); //invalid column name
pst.setString(2,"john");
pst.executeUpdate();

when i execute the above program it is giving the invalid column name
error at run time.

please solve my query.
and how to getNull value form table..
bye
 
Shailesh Chandra
Ranch Hand
Posts: 1082
Java Oracle Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by yathamshetti ramchander:
sorry, iam not clear about the answer

Seems it is continuation of other thread

Make your PreparedStatement as

PreparedStatement pst=con.prepareStatement("insert into mytab(sno,sname ) values(?,?)");


Thanks,
Shailesh
 
Parthasarathy balakrishnan
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi Yathamshetti ramchander ,

change your code and work it out

PreparedStatement pst=con.prepareStatement("insert into <<tablename>> values(?,?)");
pst.setNull(1,java.sql.Types.INTEGER); //invalid column name
pst.setString(2,"john");
pst.executeUpdate();


example can be view in :

http://www.java2s.com/Code/Java/Database-SQL-JDBC/DemoPreparedStatementSetNullforintvaluecolumn.htm



by
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic