java mysql 编程代码错误分析
代码:publicclassMSUpdate{privatestaticDBSelectrid;privatestaticDBSelectidtype;publicvoi...
代码:public class MSUpdate {
private static DBSelect rid;
private static DBSelect idtype;
public void setDBSelect(DBSelect rid, DBSelect idtype){
this.rid=rid;
this.idtype=idtype;
}
public static void MSup(String[] args) {
MSDelete a=new MSDelete();
MSDelete b=new MSDelete();
DBSelect rid=new DBSelect();
DBSelect idtype=new DBSelect();
a.setDBSelect(rid);
b.setDBSelect(idtype);
MSConnection mysql = new MSConnection();
Connection con = mysql.getConnection();
PreparedStatement pst = null;
String sql = "update radius set username=?,value=?, where rid=" + rid + ",idtype=" + idtype;
try {
pst = con.prepareStatement(sql);
System.out.println("update");
pst.setString(1,"aaaa");
pst.setString(2, "12345");
pst.executeUpdate();
pst.close();
con.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
错误:
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 'where rid=sql.DBSelect@b166b5,idtype=sql.DBSelect@cdfc9c' at line 1
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:411)
at com.mysql.jdbc.Util.getInstance(Util.java:386)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1053)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4096)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4028)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2490)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2651)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2734)
at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:2155)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2458)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2375)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2359)
at mysql.MSUpdate.MSup(MSUpdate.java:40):这句代码指的是代码中的“pst.executeUpdate();”这句有问题。求高手指点,怎么解决?
都改了,还是出错
String sql = "update radius set username=?,value=? where rid='" + rid + "',idtype='" + idtype +"'";
错误:com.mysql.jdbc.MysqlDataTruncation: Data truncation: Truncated incorrect DOUBLE value: 'sql.DBSelect@1e51060' 展开
private static DBSelect rid;
private static DBSelect idtype;
public void setDBSelect(DBSelect rid, DBSelect idtype){
this.rid=rid;
this.idtype=idtype;
}
public static void MSup(String[] args) {
MSDelete a=new MSDelete();
MSDelete b=new MSDelete();
DBSelect rid=new DBSelect();
DBSelect idtype=new DBSelect();
a.setDBSelect(rid);
b.setDBSelect(idtype);
MSConnection mysql = new MSConnection();
Connection con = mysql.getConnection();
PreparedStatement pst = null;
String sql = "update radius set username=?,value=?, where rid=" + rid + ",idtype=" + idtype;
try {
pst = con.prepareStatement(sql);
System.out.println("update");
pst.setString(1,"aaaa");
pst.setString(2, "12345");
pst.executeUpdate();
pst.close();
con.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
错误:
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 'where rid=sql.DBSelect@b166b5,idtype=sql.DBSelect@cdfc9c' at line 1
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:411)
at com.mysql.jdbc.Util.getInstance(Util.java:386)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1053)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4096)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4028)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2490)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2651)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2734)
at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:2155)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2458)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2375)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2359)
at mysql.MSUpdate.MSup(MSUpdate.java:40):这句代码指的是代码中的“pst.executeUpdate();”这句有问题。求高手指点,怎么解决?
都改了,还是出错
String sql = "update radius set username=?,value=? where rid='" + rid + "',idtype='" + idtype +"'";
错误:com.mysql.jdbc.MysqlDataTruncation: Data truncation: Truncated incorrect DOUBLE value: 'sql.DBSelect@1e51060' 展开
5个回答
展开全部
SQL语法错误,"update radius set username=?,value=?, where rid=" + rid + ",idtype=" + idtype;
你这拼接后是:update radius set username=XX,value=XX,where rid=XX,idtype=XX;
正确语法应该:update radius set username=XX,value=XX (此处应是空格,不是,) where rid=XX (此处应为and,不是,) and idtype=XX;
确定你rid和idtype字段类型和对应的传入参数的值。字段类型为字符时应改为:
where rid='" + rid + "',idtype='" + idtype +"'"; 注意,多一个单引号
截断的double值,看是不是字段值太小,插入异常。
你这拼接后是:update radius set username=XX,value=XX,where rid=XX,idtype=XX;
正确语法应该:update radius set username=XX,value=XX (此处应是空格,不是,) where rid=XX (此处应为and,不是,) and idtype=XX;
确定你rid和idtype字段类型和对应的传入参数的值。字段类型为字符时应改为:
where rid='" + rid + "',idtype='" + idtype +"'"; 注意,多一个单引号
截断的double值,看是不是字段值太小,插入异常。
更多追问追答
追问
又出新问题了,看补充
追答
能用就采纳吧~
展开全部
你的sql条件连接词少了个and,试试这个
"update radius set username=?,value=? where rid=" + rid + " and idtype='" + idtype+"'";
我不知道你的rid和idtype类型,如果是varchar2型的,在参数里像上面一样加上单引号
"update radius set username=?,value=? where rid=" + rid + " and idtype='" + idtype+"'";
我不知道你的rid和idtype类型,如果是varchar2型的,在参数里像上面一样加上单引号
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
String sql = "update radius set username=?,value=?, where rid=" + rid + ",idtype=" + idtype;
-----------------把value=?后面的逗号去掉 ,where条件中的逗号改成 and
-----------------把value=?后面的逗号去掉 ,where条件中的逗号改成 and
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
"update radius set username=?,value=?, where rid=" + rid + ",idtype=" + idtype;
--》
"update radius set username=?,value=? where rid=" + rid + "and idtype=" + idtype;
修正下 试试吧
--》
"update radius set username=?,value=? where rid=" + rid + "and idtype=" + idtype;
修正下 试试吧
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
sql语句不对吧!你把sql直接放到数据库中执行!看看哪里错了
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询