首页 \ 问答 \ 使用MySQL编写语句?(Prepared statements with MySQL?)

使用MySQL编写语句?(Prepared statements with MySQL?)

对于准备好的语句,我在语法方面遇到了一些麻烦。

我有以下代码

String query2="SELECT lname FROM school_student WHERE sid = ? ORDER BY sid;";

PreparedStatement ps = cn.prepareStatement(query2);
ps.setInt(1, 3);
ResultSet rs = ps.executeQuery(query2);

我遇到的问题是我收到此错误消息:

com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '? ORDER BY sid' at line 1

但是,当我替换“?” 在我的查询3中,查询工作正常,没有错误,并给我我想要的。 我如何设置“?”的值似乎有问题。 在我的查询? 我使用了错误的语法吗?


I am having some trouble with, what I believe to by syntax, for prepared statements.

I have the following code

String query2="SELECT lname FROM school_student WHERE sid = ? ORDER BY sid;";

PreparedStatement ps = cn.prepareStatement(query2);
ps.setInt(1, 3);
ResultSet rs = ps.executeQuery(query2);

The problem I am having is that I am getting this error message:

com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '? ORDER BY sid' at line 1

However, when I substitute the "?" in my query for a 3, the query works fine with no error and gives me what I want. There seems to be something wrong with how I am setting the value of the "?" in my query? Am I using the wrong syntax?


原文:https://stackoverflow.com/questions/15258425
更新时间:2023-05-05 18:05

最满意答案

为了输入字段值已发布到您的后端,它无法禁用。 将其更改为只读并将其样式设置为看起来像已禁用:

input[readonly] { 
    background: #CCC; 
    color: #333; 
    border: 1px solid #666 
}

In order to input field value was posted to your backend it cannot be disabled. Change it to readonly and style it to look like disabled:

input[readonly] { 
    background: #CCC; 
    color: #333; 
    border: 1px solid #666 
}

相关问答

更多
  • 当您在其外部定义lol时,您的功能原因不起作用,因为当JavaScript首次运行时, DOM尚未加载。 因此, getElementById将返回null ( 参见MDN )。 您已经找到最明显的解决方案:通过在函数内部调用getElementById ,DOM将在调用函数时被加载并准备就绪,并且将像您期望的那样找到该元素。 还有一些其他的解决方案。 一个是等到整个文档被加载,如下所示: