有人可以告诉我以下代码有什么问题吗?
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");
}
另外我得到这个错误java.sql.SQLException:没有这样的列:名称
答案 0 :(得分:1)
您没有在您的“值”子句中的“名称”字符串周围添加单引号。
String sql = "INSERT INTO Accounts (Name,Password,Level) " + "VALUES ('Name', 'passhere', 32 );";