【发布时间】:2015-01-24 11:10:03
【问题描述】:
这是我收到的消息 com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException:您的 SQL 语法有错误;检查与您的 MySQL 服务器版本相对应的手册,以在第 1 行的“complex.cox_Id='1”附近使用正确的语法
Class.forName("com.mysql.jdbc.Driver");
Connection conn=DriverManager.getConnection("jdbc:mysql://localhost:3306/optimalcms","root","123456");
Statement st=conn.createStatement();
PreparedStatement pst;
Object item = RenterRevealeds_ComplexName_ComboBox.getSelectedItem();
int value = ((Item)item).getId();
String sql="Select complex.cox_name as 'أسم المجمع',complex.cox_bld_num as 'رقم المجمع',client.clnt_name as 'أسم المسأجر',client.clnt_phone_number as 'رقم هاتف المستأجر',office.ofc_num as 'رقم المكتب',status.status_ofc_status as 'حالةالمكتب'"
+ "from client"
+ "INNER JOIN office ON office.ofc_Id = client.clnt_ofc_Id "
+ "INNER JOIN complex ON complex.cox_Id = client.clnt_cox_Id"
+ "INNER JOIN status ON status.status_Id = office.ofc_status_Id"
+ "WHERE complex.cox_Id='"+value+"'";
pst= conn.prepareStatement(sql);
ResultSet rs;
rs=pst.executeQuery();
jTable1.setModel(DbUtils.resultSetToTableModel(rs));
conn.close();
【问题讨论】:
-
我会说您的 SQL 语法有错误,您应该查看 MySQL 文档以了解要使用的正确语法。 (在运行之前打印查询应该可以帮助您查看程序发送到 MySQL 的内容以及错误的原因)
-
您确实意识到在 sql 查询中这样的字符串连接会使您的程序对 sql 注入攻击敞开大门?
-
我确实在运行程序及其工作之前检查了查询