INSERT SQL in Java

Posted by Pierre on Stack Overflow See other posts from Stack Overflow or by Pierre
Published on 2010-05-27T12:36:52Z Indexed on 2010/05/27 12:41 UTC
Read the original article Hit count: 175

Filed under:
|
|

Hello.

I have a Java application and I want to use SQL database. I have a class for my connection :


public class SQLConnection{
    private static String url = "jdbc:postgresql://localhost:5432/table";
    private static String user = "postgres";
    private static String passwd = "toto";
    private static Connection connect;
    public static Connection getInstance(){
        if(connect == null){
            try {
                connect = DriverManager.getConnection(url, user, passwd);
            } catch (SQLException e) {
                JOptionPane.showMessageDialog(null, e.getMessage(), "Connection Error", JOptionPane.ERROR_MESSAGE);
            }
        }       
        return connect; 
    }
}

And now, in another class I succeeded to print my values but when I attempt to insert a value nothing is happening ...

Here's my code :


try {
Statement state = SQLConnection.getInstance().createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
Statement state2 = SQLConnection.getInstance().createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_UPDATABLE);
state2.executeUpdate("INSERT INTO table(field1) VALUES (\"Value\")"); // Here's my problem
ResultSet res = state.executeQuery("SELECT * FROM plateau");

© Stack Overflow or respective owner

Related posts about java

Related posts about sql