This week's giveaway is in the EJB and other Java EE Technologies forum.
We're giving away four copies of EJB 3 in Action and have Debu Panda, Reza Rahman, Ryan Cuprak, and Michael Remijan on-line!
See this thread for details.
The moose likes JDBC and the fly likes setting the null  and getting null Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "setting the null  and getting null" Watch "setting the null  and getting null" New topic
Author

setting the null and getting null

ramchander yshetti
Ranch Hand

Joined: Apr 22, 2006
Posts: 97
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

Joined: Aug 13, 2004
Posts: 1081

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


Gravitation cannot be held responsible for people falling in love ~ Albert Einstein
Parthasarathy balakrishnan
Greenhorn

Joined: Apr 20, 2007
Posts: 14
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


Thanks and Regards,<br />-------------------<br />Parthasarathy Balakrishnan,<br />Bangalore.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: setting the null and getting null
 
Similar Threads
SQLException: Invalid column type when setting null values to NUMBER type columns
Getting Errror ORA-00904: invalid column name
Hibernate .hbm.xml - Referential Integrity constraint
Searching words in VARCHAR2 & CLOB
Could not parse mapping document from resource register.hbm.xml