aspose file tools*
The moose likes JDBC and the fly likes error in inserting string into database Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "error in inserting string into database" Watch "error in inserting string into database" New topic
Author

error in inserting string into database

Rajesh Chandra
Ranch Hand

Joined: Jun 13, 2005
Posts: 55
Hello pals,
this is a code snippet in which I insert two strings into MSACESS .while
Im able to insert the string myname,Im not able to insert pc.Is there any problem with making more than one prepared statement on a connection object or is it some silly sql syntax error?
public void storePhone(String x,String y){
myname=x;pc=y;
try{
System.out.println("in storephone pc="+pc);

String sqlname="INSERT INTO PHONEDIARY(NAME)VALUES(?)";
ps=con.prepareStatement(sqlname);
ps.setString(1,myname);
ps.executeUpdate();


String sqlphone="INSERT INTO PHONEDIARY(PHONENUMBER)VALUES(?)";
ps2=con.prepareStatement(sqlphone);
ps2.setString(2,pc);

ps2.executeUpdate();

}
catch(Exception e){}
}
Thanks in advance for the help!
regs-Rajesh
Makarand Parab
Ranch Hand

Joined: Dec 10, 2004
Posts: 121
Hi Rajesh
Please post the exception, then only we can find the exact problem.

Regards
Makarand Parab
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 29249
    
139

Rajesh,
Some databases don't support having multiple statements open on a connection at the same time. In any case, you want to close your PreparedStatement object as soon as you are done with it to conserve resources. In this case, that would be immediately after the first update.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: error in inserting string into database
 
Similar Threads
layout problems
layout problems
How to get a blank ResultSet to do update?
how to enter date object in ms access database
Pass variables in INSERT statement