当前位置: 代码迷 >> Eclipse >> sql传递参数有关问题
  详细解决方案

sql传递参数有关问题

热度:110   发布时间:2016-04-23 14:39:12.0
sql传递参数问题
Connection   conn=null;
Statement   stmt=null;
String   sql= "update   doc   set   Contents= ' "+content+ " '   where   DocURL= ' "+url+ " ' ";
try
{
Class.forName( "org.gjt.mm.mysql.Driver ");
conn=DriverManager.getConnection( "jdbc:mysql://localhost:3306/invertedindex ", "root ", "sa ");
stmt=conn.createStatement();
stmt.executeUpdate(sql);
}
catch(Exception   e)
{
e.printStackTrace();
}

说我sql语法有错,我只知道在c#中传参可以这么写: ' "+para+ " ',但是不知道java里是不是这样写的

------解决方案--------------------
当然没问题。。。
建议楼主检查一下参数的类型是否匹配
------解决方案--------------------

Connection conn=null;
Statement stmt=null;
String sql= "update doc set Contents= "+ " ' "+content+ " ' "+ " where DocURL= "+ " ' "+url+ " ' ";
try
{
Class.forName( "org.gjt.mm.mysql.Driver ");
conn=DriverManager.getConnection( "jdbc:mysql://localhost:3306/invertedindex ", "root ", "sa ");
stmt=conn.createStatement();
stmt.executeUpdate(sql);
}
catch(Exception e)
{
e.printStackTrace();
}


单引号的地方有毛病
------解决方案--------------------
兄弟干嘛这么麻烦,用预处理会话,代码简洁直观, ' " " '在C#里就很不好用,多了非常混乱,可以用StringBuffer
  相关解决方案