我尝试将新数据添加到SQLite数据库中。连接已成功建立,但是,当我添加新数据时,DB表中未显示任何内容。谁能帮我解决这个问题?谢谢
package database;
import java.sql.*;
public class Database {
public static void main(String[] args) {
// TODO code application logic here
Connection c = null;
try {
Class.forName("org.sqlite.JDBC");
c = DriverManager.getConnection("jdbc:sqlite:admin.db");
System.out.println("Connection is established");
String SQLadd = "insert into" + "admins(user_name,password)" + "values('sachin', 'kafle')";
Statement stmt = c.createStatement();
stmt.executeUpdate(SQLadd);
//c.commit();
//c.close();
}
catch (Exception e) {
System.out.println("Can not connect to database");
//System.exit(0);
}
}
}
答案 0 :(得分:1)
我认为您也应该在into
之后给admins
和values
之间留空格,或者像下面这样:
String SQLadd = "insert into admins(user_name,password) values('sachin', 'kafle')";
希望对您有帮助...:)