Win a copy of Java Mock Exams (software) this week in the Programmer Certification (OCPJP) 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
 
Happiness is not a goal ... it's a by-product of a life well lived - Eleanor Roosevelt. Tiny ad:
the new thread boost feature: great for the advertiser and smooth for the coderanch user
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!