• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

error in inserting string into database

 
Rajesh Chandra
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 121
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Rajesh
Please post the exception, then only we can find the exact problem.

Regards
Makarand Parab
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34863
369
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic