Java SQLite:无此类列错误 [英] Java SQLite : no such column error
本文介绍了Java SQLite:无此类列错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在编写一个Java应用程序,该应用程序必须将记录添加到数据库中.一切正常,直到我想向数据库添加局部变量为止(我认为我将括号放在错误的地方或其他原因).无论如何,我已经厌倦了寻找问题的机会,并希望获得一些帮助.
I'm writing a Java app which has to add a record to a database. Everything works fine until I want to add a local variable to the database (I think I'm placing my parentheses wrong or something). Anyway, I'm tired of looking for the problem and would appreciate some help.
我的代码:
public void newUser(int userID, String userName, String credentials) {
try {
Class.forName("org.sqlite.JDBC");
conn = DriverManager
.getConnection("jdbc:sqlite:c:/temp/alarmsystem.db");
Statement statement = conn.createStatement();
statement.execute("insert into Users values(" + 1 + "," + userName
+ "," + "'Helloskit'" + ") ");
core.printToConsole("created");
ResultSet rs = statement.executeQuery("select * from Users");
while (rs.next()) {
String s = rs.getString("Username");
core.printToConsole("name = " + s);
}
} catch (Exception e) {
}
}
错误:
java.sql.SQLException: no such column: Tombellens
at org.sqlite.DB.throwex(DB.java:288)
at org.sqlite.NestedDB.prepare(NestedDB.java:115)
at org.sqlite.DB.prepare(DB.java:114)
at org.sqlite.Stmt.execute(Stmt.java:82)
at me.server.DBCommunications.DBConnection.newUser(DBConnection.java:59)
at me.server.Core.Core.newUser(Core.java:61)
at me.server.LocalUser.Console.main(Console.java:72)
谢谢汤姆
推荐答案
问题出在查询中. userName
变量未用引号引起来
The problem is the in query. The userName
variable is not enclosed in quotes
使用以下代码:
statement.execute("insert into Users values(" + 1 + ",'" + userName + "'," + "'Helloskit'" +") ");
这篇关于Java SQLite:无此类列错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文