Click here to Skip to main content
15,887,812 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am having problems inserting data into a postgres table created using java. The created table part of the code works fine, its only when I am inserting values into the table that nothing happens. The code I am using to populate the table tt is:

What I have tried:

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
String txt1 = jTextField1.getText();
int number = Integer.parseInt(txt1);
String name= jTextField2.getText();
String txt3 = jTextField3.getText();
int mean = Integer.parseInt(txt3);
Connection c = null;
Statement stmt = null;
try {
Class.forName("org.postgresql.Driver");
c = DriverManager.getConnection("jdbc:postgresql://localhost:5432/tst", "postgres", "21262050");
c.setAutoCommit(false);
System.out.println("Opened database successfully");
String sql = "INSERT INTO tt(noun, max, nbr) VALUES(?, ?, ?)";
PreparedStatement pst = c.prepareStatement(sql);
pst.setString(1, name);
pst.setInt(2,mean );
pst.setInt(3, number);

pst.executeUpdate();

} catch (SQLException ex) {
Logger.getLogger(insrt.class.getName()).log(Level.SEVERE, null, ex);
}


catch(Exception e){
e.printStackTrace();
}

}

public static void main(String args[]) {

java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new insrt().setVisible(true);
}
});
}
Posted
Updated 26-Apr-16 4:14am

1 solution

resolved just i have to add c.commit() after pst.executeUpdate();
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900