aspose file tools*
The moose likes JDBC and the fly likes PreparedStatement, how can i skip a column? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "PreparedStatement, how can i skip a column?" Watch "PreparedStatement, how can i skip a column?" New topic
Author

PreparedStatement, how can i skip a column?

carlos flamenco
Greenhorn

Joined: Feb 28, 2001
Posts: 7
Hi,
I want to insert values into a table that has four columns, I only want to update columns one and three though! Sometimes I will be doing an update instead and will update columns 2,3 and 4. My problem is that I keepp getting requested to update the second column, when in fact i want the value there to remain the same.Here is a snippet of my code anyway, any help would be greatly appreciated!
Statement stmt = conn.createStatement();
PreparedStatement insertuser = conn.prepareStatement("INSERT INTO TEST.THE_USER VALUES(?,?)");
insertuser.clearParameters();
insertuser.setString(1,userid);
insertuser.setString(3,last_update);
insertuser.executeUpdate();
Anusaya Sehgal
Greenhorn

Joined: Nov 09, 2001
Posts: 2
Originally posted by carlos flamenco:
Hi,
I want to insert values into a table that has four columns, I only want to update columns one and three though! Sometimes I will be doing an update instead and will update columns 2,3 and 4. My problem is that I keepp getting requested to update the second column, when in fact i want the value there to remain the same.Here is a snippet of my code anyway, any help would be greatly appreciated!
Statement stmt = conn.createStatement();
PreparedStatement insertuser = conn.prepareStatement("INSERT INTO TEST.THE_USER VALUES(?,?)");
insertuser.clearParameters();
insertuser.setString(1,userid);
insertuser.setString(3,last_update);
insertuser.executeUpdate();


If I understand ur problem then the solutions is
PreparedStatement insertuser= con.prepareStatement("INSERT INTO TEST.THE_USER(userid,last_update) VALUES(?,?)");
insertuser.clearParameters();
insertuser.setString(1,userid);
insertuser.setString(2,last_update);
insertuser.executeUpdate();
i hope this helps u

[This message has been edited by Anusaya Sehgal (edited November 09, 2001).]
ayman ms
Greenhorn

Joined: Mar 02, 2014
Posts: 1
suppose i have two column named "name", "email"
then i can use this code to insert values to the database containing table( std_tb)
with two column


if i want to insert second column only then i can use this code to same table containing two column

but don't forget to set first column a null value , if you are using wamp or xampp then ,you can do this by going "http://localhost/phpmyadmin/" then access to your table then put tick mark on null
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: PreparedStatement, how can i skip a column?