gpt4 book ai didi

javascript - 如何将java字符串插入数据库表?

转载 作者:行者123 更新时间:2023-12-02 11:45:23 24 4
gpt4 key购买 nike

我有一个通过 jsp 文件管理的数据库。我想向其中添加一些数据,但我需要从字符串变量中获取数据。我尝试了以下代码,但“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+ "');"; 

关于javascript - 如何将java字符串插入数据库表?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48242707/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com