我試圖做一個動態的刪除查詢。動態刪除查詢
什麼即時通訊基本上試圖做的是首先抓住任何表(主鍵)的第一列的名稱。然後,我用另一個查詢從該表中刪除,雖然我得到一個nullpointerexception?
哦,主鍵不是像1,2,3,4,5等INT。它形成了S1,S2,S3,S4,S5等,並且類型是TEXT。
Connection c = null;
Statement stmt = null;
try {
Class.forName("org.sqlite.JDBC");
c = DriverManager.getConnection("jdbc:sqlite:test.db");
c.setAutoCommit(true);
System.out.println("Opened database successfully");
ResultSet rs = stmt.executeQuery("SELECT * FROM "+tablename);
ResultSetMetaData rsmd = rs.getMetaData();
FirstColumn = rsmd.getColumnName(1);
String query = "DELETE FROM "+tablename+" WHERE " +FirstColumn+ " = " +row;
stmt = c.createStatement();
stmt.executeUpdate(query);
stmt.close();
c.close();
字符串'query'中'row'的撇號? –
你究竟在做什麼? –
一般來說,堆棧跟蹤會顯示引起NullPointerException的行,可能確切的變量爲空。 –