• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

error in inserting string into database

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

Regards
Makarand Parab
 
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic