我有一个通过jsp文件管理的数据库。我想向其中添加一些数据,但是我需要从String变量中获取数据。
我尝试了以下代码,但“ VALUES”参数不接受变量。有什么帮助吗?

function UploadNot() {
     <%
          String NotificationToUpload = "Test Notification";
          Class.forName("org.sqlite.JDBC");
          conn = DriverManager.getConnection("jdbc:sqlite:d:\\Databases\\DataBase1.db");
          stat = conn.createStatement();
          String sql = "INSERT INTO Nots (Notifications) " +
               "VALUES (NotificationToUpload);";  //ERROR here, Does not accept variables, only direct Strings
          stat.executeUpdate(sql);
     %>
}

最佳答案

您忘记了“ +”运算符以连接您的值。

String sql = "INSERT INTO Nots (Notifications) VALUES ('" +NotificationToUpload+ "');";

08-05 08:29
查看更多