![](https://iknow-base.cdn.bcebos.com/lxb/notice.png)
java Eclipse连SQL Server 2005中SQL语句有误,帮忙看看吧!!急!!
com.microsoft.sqlserver.jdbc.SQLServerException:'1'附近有语法错误。atcom.microsoft.sqlserver....
com.microsoft.sqlserver.jdbc.SQLServerException: '1' 附近有语法错误。
at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDatabaseError(SQLServerException.java:196)
at com.microsoft.sqlserver.jdbc.SQLServerStatement.getNextResult(SQLServerStatement.java:1454)
at com.microsoft.sqlserver.jdbc.SQLServerStatement.doExecuteStatement(SQLServerStatement.java:786)
at com.microsoft.sqlserver.jdbc.SQLServerStatement$StmtExecCmd.doExecute(SQLServerStatement.java:685)
at com.microsoft.sqlserver.jdbc.TDSCommand.execute(IOBuffer.java:4026)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.executeCommand(SQLServerConnection.java:1416)
at com.microsoft.sqlserver.jdbc.SQLServerStatement.executeCommand(SQLServerStatement.java:185)
at com.microsoft.sqlserver.jdbc.SQLServerStatement.executeStatement(SQLServerStatement.java:160)
at com.microsoft.sqlserver.jdbc.SQLServerStatement.executeUpdate(SQLServerStatement.java:642)
at frame.Mainframe.jbtn2MouseClicked(Mainframe.java:496)
at frame.Mainframe.access$1(Mainframe.java:460)
at frame.Mainframe$2.mouseClicked(Mainframe.java:154)
代码如下
DataCon dataCon = new DataCon();
Connection conn = dataCon.createConn();
Statement stmm = null;
try {
String tt=null;
stmm = conn.createStatement();
String ttt="update road set 道路长度=" + ldcd + "where 道路名称='" + ld + "'";
stmm.executeUpdate(ttt);
if(cdh=="1号车道" && cdfx=="左行车道"){
tt="update road set 1号车道左行车道数 = " + cds + " where 道路名称='" + ld + "'";
}else if(cdh=="1号车道" && cdfx=="直行车道"){
tt="update road set 1号车道直行车道数 = " + cds + " where 道路名称='" + ld + "'";
}else if(cdh=="1号车道" && cdfx=="右行车道"){
tt="update road set 1号车道右行车道数 = " + cds + " where 道路名称='" + ld + "'";
}else if(cdh=="2号车道" && cdfx=="左行车道"){
tt="update road set 2号车道左行车道数 = " + cds + " where 道路名称='" + ld + "'";
}else if(cdh=="2号车道" && cdfx=="直行车道"){
tt="update road set 2号车道直行车道数 = " + cds + " where 道路名称='" + ld + "'";
}else if(cdh=="2号车道" && cdfx=="右行车道"){
tt="update road set 2号车道右行车道数 = " + cds + " where 道路名称='" + ld + "'";
}
stmm.executeUpdate(tt);
Mainframe.java:496指向stmm.executeUpdate(tt);
帮忙看看那里有错吧,拜托!! 展开
at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDatabaseError(SQLServerException.java:196)
at com.microsoft.sqlserver.jdbc.SQLServerStatement.getNextResult(SQLServerStatement.java:1454)
at com.microsoft.sqlserver.jdbc.SQLServerStatement.doExecuteStatement(SQLServerStatement.java:786)
at com.microsoft.sqlserver.jdbc.SQLServerStatement$StmtExecCmd.doExecute(SQLServerStatement.java:685)
at com.microsoft.sqlserver.jdbc.TDSCommand.execute(IOBuffer.java:4026)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.executeCommand(SQLServerConnection.java:1416)
at com.microsoft.sqlserver.jdbc.SQLServerStatement.executeCommand(SQLServerStatement.java:185)
at com.microsoft.sqlserver.jdbc.SQLServerStatement.executeStatement(SQLServerStatement.java:160)
at com.microsoft.sqlserver.jdbc.SQLServerStatement.executeUpdate(SQLServerStatement.java:642)
at frame.Mainframe.jbtn2MouseClicked(Mainframe.java:496)
at frame.Mainframe.access$1(Mainframe.java:460)
at frame.Mainframe$2.mouseClicked(Mainframe.java:154)
代码如下
DataCon dataCon = new DataCon();
Connection conn = dataCon.createConn();
Statement stmm = null;
try {
String tt=null;
stmm = conn.createStatement();
String ttt="update road set 道路长度=" + ldcd + "where 道路名称='" + ld + "'";
stmm.executeUpdate(ttt);
if(cdh=="1号车道" && cdfx=="左行车道"){
tt="update road set 1号车道左行车道数 = " + cds + " where 道路名称='" + ld + "'";
}else if(cdh=="1号车道" && cdfx=="直行车道"){
tt="update road set 1号车道直行车道数 = " + cds + " where 道路名称='" + ld + "'";
}else if(cdh=="1号车道" && cdfx=="右行车道"){
tt="update road set 1号车道右行车道数 = " + cds + " where 道路名称='" + ld + "'";
}else if(cdh=="2号车道" && cdfx=="左行车道"){
tt="update road set 2号车道左行车道数 = " + cds + " where 道路名称='" + ld + "'";
}else if(cdh=="2号车道" && cdfx=="直行车道"){
tt="update road set 2号车道直行车道数 = " + cds + " where 道路名称='" + ld + "'";
}else if(cdh=="2号车道" && cdfx=="右行车道"){
tt="update road set 2号车道右行车道数 = " + cds + " where 道路名称='" + ld + "'";
}
stmm.executeUpdate(tt);
Mainframe.java:496指向stmm.executeUpdate(tt);
帮忙看看那里有错吧,拜托!! 展开
5个回答
展开全部
首先:很明显第一条ttt语法有错误(where 前面加空格)
其次:tt语句里面的字段名称是否跟数据库中的字段名相同(怀疑数据库中的字段名不应该是中文啊)
其次:tt语句里面的字段名称是否跟数据库中的字段名相同(怀疑数据库中的字段名不应该是中文啊)
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
road 表的字段大部分是char吧
"update road set 道路长度=" + ldcd + "where 道路名称='" + ld + "'";
改成
"update road set 道路长度='" + ldcd + "' where 道路名称='" + ld + "'";
看这里两边有 ' '
' " + ldcd + " '
"update road set 道路长度=" + ldcd + "where 道路名称='" + ld + "'";
改成
"update road set 道路长度='" + ldcd + "' where 道路名称='" + ld + "'";
看这里两边有 ' '
' " + ldcd + " '
更多追问追答
追问
不是呀,除了道路名称是char,其他定义的是int型啊
追答
那就是空格罗
"update road set 道路长度=" + ldcd + "where 道路名称='" + ld + "'";
"update road set 道路长度=" + ldcd + " where 道路名称='" + ld + "'";
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
字段的首字母为数字的话,还是把列名用[]包起来,如:
[1号车道右行车道数]=
[1号车道右行车道数]=
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
用preparedstatement,别用statement
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询