import java.sql.DriverManager;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

public class PreparedStatementTest {
    
    private static final String insertQuery = "INSERT INTO entityids (eid_entityname, eid_lasteid) VALUES (?, ?)";

    public static void main(String args[]) throws Exception {
        Connection testConn = null;
        PreparedStatement ps = null;

        try {
            Class.forName("com.mysql.jdbc.Driver");
            //testConn = DriverManager.getConnection("jdbc:mysql://localhost:3306/test?useServerPrepStmts=false", "test", "test");
            testConn = DriverManager.getConnection("jdbc:mysql://localhost:3306/test?autoGenerateTestcaseScript=true", "test", "test");

            ps = testConn.prepareStatement(insertQuery);
            ps.setString(1, "TestEntityName");
            ps.setLong(2, 50);

            int count = ps.executeUpdate();
            System.out.println(count);
        } catch (ClassNotFoundException cnfe) {
            System.err.println("MySQL driver class missing");
        } catch (SQLException se) {
            System.err.println("SQL Error occured:");
            se.printStackTrace();
        } finally {
            if(ps != null) {
                try {
                    ps.close();
                    ps = null;
                } catch (SQLException se) {
                    se.printStackTrace();
                }
            }

            if(testConn != null) {
                try {
                    testConn.close();
                    testConn = null;
                } catch (SQLException se) {
                    se.printStackTrace();
                }
            }
        }
    }
    
}

