JAVA mysql语句报错 Truncated incorrect DOUBLE value: '??? ??·'

publicintdeletes(Stringid,Connectionc){inta=0;Strings="deletefromsaccountwhereid='"+i... public int deletes(String id,Connection c){
int a=0;
String s="delete from saccount where id = '" + id + "' ";
try {
PreparedStatement ps=c.prepareStatement(s);
a=ps.executeUpdate();
return a;
} catch (Exception e) {
e.printStackTrace();
return a;
}
}
展开
 我来答
牲口圣者
2016-07-07 · TA获得超过525个赞
知道小有建树答主
回答量:466
采纳率:50%
帮助的人:341万
展开全部
你的id在数据库中类型应该是double的,但是你传了个字符串进去了,改成这样
String s="delete from saccount where id = " + id;
本回答被提问者采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
0809cccccy
2018-04-11 · TA获得超过1.3万个赞
知道小有建树答主
回答量:74
采纳率:98%
帮助的人:1.1万
展开全部

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):

本回答被网友采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
匿名用户
2016-07-07
展开全部
String s="delete from saccount where id = '" + id + "' ";

改成:
String s="delete from saccount where id = ?";

PreparedStatement ps=c.prepareStatement(s);
a=ps.executeUpdate();
两行中间加一行(set根据id的类型选):
ps.setInt(1,id);
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 更多回答(1)
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式