gpt4 book ai didi

java - 插入数据时出现 SQL 异常 : com. microsoft.sqlserver.jdbc.SQLServerException

转载 作者:行者123 更新时间:2023-12-01 11:26:22 24 4
gpt4 key购买 nike

SQL Exception: com.microsoft.sqlserver.jdbc.SQLServerException: Incorrect syntax near 'st'.

这是我整个程序代码的数据插入部分。我猜异常就在这里

String SQL;
stmt = con.createStatement();
SQL = "INSERT INTO formtable (clgname,clgaddres,hmob,hemail,pmonth,pyear,sname,gender,dob,paddr,smob,semail,tenboard,tenyop,tenper,tendiv,twscboard,twscyop,twscper,twscdiv,bscbcaboard,bscbcayop,bscbcaper,bscbcadiv,mscboard,mscyop,mscper,mscdiv,frsem,scsem,thsem,frthsem,hardware,os,languages,dbms,communication,stporganization,stpobjective,stphardware,stpsoftware,stpduration,othertraining) VALUES ('"+combo1+"','"+ta1+"','"+text1+"','"+text2+"','"+combo2+"','"+text3+"','"+text4+"','"+rbdtext+"','"+date+"','"+ta2+"','"+text5+"','"+text6+"','"+tboard+"','"+tyop+"','"+tper+"',"+tdiv+"','"+twboard+"','"+twyop+"','"+twper+"','"+twdiv+"','"+bsbcboard+"','"+bsbcyop+"','"+bsbcper+"','"+bsbcdiv+"','"+mscboard+"','"+mscyop+"','"+mscper+"','"+mscdiv+"','"+fsem+"','"+ssem+"','"+tsem+"','"+fosem+"','"+text7+"','"+text8+"','"+text9+"','"+text10+"','"+text11+"','"+text12+"','"+ta3+"','"+text13+"','"+text14+"','"+text15+"','"+ta4+"')";
int rowsEffected = stmt.executeUpdate(SQL);

最佳答案

您在查询中错过了单引号 在“+tdiv+”'

应该是

'"+tdiv+"'

使用以下查询

String SQL;
stmt = con.createStatement();
SQL = "INSERT INTO formtable (clgname,clgaddres,hmob,hemail,pmonth,pyear,sname,gender,dob,paddr,smob,semail,tenboard,tenyop,tenper,tendiv,twscboard,twscyop,twscper,twscdiv,bscbcaboard,bscbcayop,bscbcaper,bscbcadiv,mscboard,mscyop,mscper,mscdiv,frsem,scsem,thsem,frthsem,hardware,os,languages,dbms,communication,stporganization,stpobjective,stphardware,stpsoftware,stpduration,othertraining) VALUES ('"+combo1+"','"+ta1+"','"+text1+"','"+text2+"','"+combo2+"','"+text3+"','"+text4+"','"+rbdtext+"','"+date+"','"+ta2+"','"+text5+"','"+text6+"','"+tboard+"','"+tyop+"','"+tper+"','"+tdiv+"','"+twboard+"','"+twyop+"','"+twper+"','"+twdiv+"','"+bsbcboard+"','"+bsbcyop+"','"+bsbcper+"','"+bsbcdiv+"','"+mscboard+"','"+mscyop+"','"+mscper+"','"+mscdiv+"','"+fsem+"','"+ssem+"','"+tsem+"','"+fosem+"','"+text7+"','"+text8+"','"+text9+"','"+text10+"','"+text11+"','"+text12+"','"+ta3+"','"+text13+"','"+text14+"','"+text15+"','"+ta4+"')";
int rowsEffected = stmt.executeUpdate(SQL);

关于java - 插入数据时出现 SQL 异常 : com. microsoft.sqlserver.jdbc.SQLServerException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30773430/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com