• 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
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

Regarding Data Insertion

 
Ranch Hand
Posts: 268
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
i am unable to insert values from my GUI when i click add button. The Listener for the button is as follows:


add.addActionListener(new ActionListener()
{

public void actionPerformed(ActionEvent ae)
{
if(ae.getActionCommand()=="Add")
{
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection conn = DriverManager.getConnection("jdbc.odbc.addissue","library","bismillah");
PreparedStatement ps = conn.prepareStatement("INSERT INTO addissue VALUES(?,?,?,?)");

String str0 = addtf.getText();
String str1 = addtf1.getText();
String str2 = addtf2.getText();
String str3 = addtf3.getText();
ps.setInt(1,Integer.parseInt(str0));
ps.setString(2,str1);
ps.setString(3,str2);
ps.setString(4,str3);
ps.executeUpdate();
conn.close();
}
catch(Exception ce)
{
}
}
}
});

 
Bartender
Posts: 1561
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

if(ae.getActionCommand()=="Add")



This is a bad idea as you should not compare Strings with ==. Compare with equals(...) or equalsIgnoreCase(...). If this doesn't solve your problem, then perhaps this post should be moved to the database section as it doesn't look to be a UI problem.
 
Bartender
Posts: 4121
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Also,


There could be a SQLException or any kind of runtime exception being thrown, and it will never be printed out because of this... at least do a ce.printStackTrace().
 
Hot dog! An advertiser loves us THIS much:
New web page for Paul's Rocket Mass Heaters movies
https://coderanch.com/t/785239/web-page-Paul-Rocket-Mass
reply
    Bookmark Topic Watch Topic
  • New Topic