【发布时间】:2014-01-13 07:43:06
【问题描述】:
我有一个 java 桌面应用程序。 我正在尝试将两个文本字段中的数据插入到数据库中。 但是遇到一些运行时错误。 帮我解决它。
这是我的代码 sn-p
final String s1 = t1.getText();
final String s2 = t2.getText();
jb.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
String host = "jdbc:derby://localhost:1527/Details";
String uName = "rajil";
String uPass = "rajil";
try {
Connection con = DriverManager.getConnection(host, uName,uPass);
Statement st = con.createStatement();
String q1 = "insert into name (name,id) values('" + s1 + "','" + s2 + "')";
st.executeQuery(q1);
} catch (SQLException ex) {
Logger.getLogger(DBConnect.class.getName()).log(Level.SEVERE, null, ex);
}
}
});
【问题讨论】:
-
你遇到了什么错误?
-
哪里出错了?
-
java.sql.SQLException:executeQuery 方法不能用于更新。在 org.apache.derby.client.am.SQLExceptionFactory40.getSQLException(Unknown Source) at org.apache.derby.client.am.SqlException.getSQLException(Unknown Source) at org.apache.derby.client.am.Statement.executeQuery (来源不明)
-
没有语法错误。它的运行时
-
不要将堆栈跟踪放在 cmets 中。相反,edit the question..
标签: java sql swing jdbc javadb