[Microsoft][ODBC Microsoft Access Driver] 参数不足,期待是 1的原因:
查看sql语句 如果字段数据类型是文本 则需要加‘’。
import java.sql.*;
public class Test {
public static void main(String[] args) {
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("jdbc:odbc:hxl");
Statement stmt=con.createStatement();
String name="zhangsan";
// String sqlStr="select * from user where"+" name= "+name+" ";//抛出异常,参数不足,期待是1
String sqlStr="select * from user where"+" name= '"+name+"' ";//修改上句为正确格式
// String sqlStr="select * from user where name='zhangsan'";//'zhangsan'正确格式
ResultSet rst=stmt.executeQuery(sqlStr);
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
阅读(1783) | 评论(0) | 转发(0) |