mercredi 23 décembre 2015

Passing a variable into a table through a function

Can someone please tell me what's wrong with the following code please?

public static void Insert(String Name) {
    Connection connection = null;
    Statement st = null;
    try {
        Class.forName("org.sqlite.JDBC");
        connection = DriverManager.getConnection("jdbc:sqlite:E:\\test.db");
        connection.setAutoCommit(false);
        st = connection.createStatement();
        String sql = "INSERT INTO Accounts (Name,Password,Level) " +
                   "VALUES (Name, 'passhere', 32 );"; 
        st.executeUpdate(sql);

        st.close();
        connection.commit();
        connection.close();
    } catch (Exception e) {
        System.err.println(e.getClass().getName() + ": " + e.getMessage());
    }
    System.out.println("Records created successfully");
}

Additionally I get this error java.sql.SQLException: no such column: Name

Aucun commentaire:

Enregistrer un commentaire