我正在尝试将用户名添加到 .accdb 本地数据库中。我的代码如下:
try
{
String sql = "INSERT INTO Users VALUES('?');";
System.out.println("SQL : " + sql);
System.out.println("USER : " + user);
PreparedStatement stmt = database.prepareStatement(sql);
System.out.println("Statement : " + stmt);
stmt.setString(1, user);
System.out.println("Statement : " + stmt);
ResultSet results = stmt.executeQuery();
System.out.println("Results : " + results);
}
catch(SQLException sqlEx)
{
System.out.println("* Cannot execute insertion! *");
sqlEx.printStackTrace();
System.exit(1);
}
控制台输出是:
SQL : INSERT INTO Users VALUES('?');
USER : TEST
Statement : sun.jdbc.odbc.JdbcOdbcPreparedStatement@1bf73fa
Exception in thread "Thread-0" java.lang.NullPointerException
at sun.jdbc.odbc.JdbcOdbcPreparedStatement.clearParameter (JdbcOdbcPreparedStatement.java:1023)
at sun.jdbc.odbc.JdbcOdbcPreparedStatement.setChar (JdbcOdbcPreparedStatement.java:3057)
at sun.jdbc.odbc.JdbcOdbcPreparedStatement.setString (JdbcOdbcPreparedStatement.java:766)
at MultiEchoServer.addRegisteredUser(MultiEchoServer.java:100)
at ClientHandler.run(MultiEchoServer.java:339)
谢谢你的帮助!