插入数据时出错 [英] Error inserting data

查看:96
本文介绍了插入数据时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

st.executeUpdate("INSERT INTO studdet ( NAME, EMAIL,phoneno,adress )values (''+name+'',''+email+'',+ph+,''+ad+'')");



com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException:您的SQL语法有错误;在第1行的



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 ''''+ad+'')'' at line 1

推荐答案

就像您在这里遇到一些问题.首先是拼写之一.我认为您可能在查询中拼写了错误的姓名(studdet代替学生,aaddress代替地址,等等.)首先检查那里.

接下来,看起来您要插入的值是变量,但是您没有正确地从字符串中转义它们.这是您应该怎么做的方法:
It looks like you have a few problems here. The first is one of spelling. I think you might have spelled the names in your query wrong (studdet instead of student, adress instead of address, etc.) Check there first.

Next, it looks like the values you are inserting are variables but you are not properly escaping them from the string. This is how you should do it:
st.executeUpdate("INSERT INTO studdet ( NAME, EMAIL,phoneno,adress )values ('"+name+"','"+email+"',"+ph+",'"+ad+"')");


请注意,双引号会转义字符串并允许正确访问变量.

附带说明一下,我建议您在首先确认变量是干净的"(没有可能导致SQL注入攻击的特殊字符)之前,不要将变量直接放入SQL语句中.


Notice the double-quotes to escape the string and allow the variable to be accessed properly.

As a side note, I would recommend that you not put variables directly into a SQL statement until you have first verified that they are "clean" (no special characters that could lead to a SQL Injection attack).



插入值必须包含在''"+ yourvariable +"''

因此请尝试如下操作:

inserting values in string must be enclosed in ''"+ yourvariable +"''

so try as follows:

values ('"+name+"','"+email+"',+ph+,'"+ad+"')");




如果您有解决方案,请回答...

谢谢




make it answer if you got your solution...

Thanks


您确定它的地址而不是地址吗?
Are you sure its adress and not address?


这篇关于插入数据时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆