jdbc连接access数据库 你的SQL语句是什么样的?去掉jdbc:odbc:Driver前后的空格String url = "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)}; DBQ=C:/CDShop.mdb"; 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 sqlstr呢?可能查询语句的问题 sql语句仔细 仔细检查一下 可以把sql输出来看看 [Microsoft][ODBC Microsoft Access Driver]参数不足,期待是1。很可能是查询语句的问题! String ms = "sun";我的查询语句是:sqlstr = "select * from employee where employeeName = ms"; 应该没有错误 access odbc 驱动未加载,有本书上是这么说的,但不知道怎么解决我修改成这样:try{Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");string url = "jdbc:odbc:shop";Connection conn = DriverManager.getConnection(url, "", "");Statement stmtNew = conn.createStatement();resultset s= stmtNew.executeQuery(sqlstr);} catch(SQLException e1) { System.out.println(e1.getMessage()); } catch(Exception e2) { System.out.println("出错了"); }shop 是我建的odbc数据源名称结果运行过程中显示同样错误为:[Microsoft][ODBC Microsoft Access Driver]参数不足,期待是1。 完整的语句是String ms = "sun";sqlstr = "select * from employee where employeeName = ms";try{Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");string url = "jdbc:odbc:shop";Connection conn = DriverManager.getConnection(url, "", "");Statement stmtNew = conn.createStatement();resultset s= stmtNew.executeQuery(sqlstr);} catch(SQLException e1) { System.out.println(e1.getMessage()); } catch(Exception e2) { System.out.println("出错了"); }shop 是我建的odbc数据源名称还是同样的错误,数据源的设置并没有错 String ms = "sun";sqlstr = "select * from employee where employeeName =" + ms;try{Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");string url = "jdbc:odbc:shop";Connection conn = DriverManager.getConnection(url);Statement stmtNew = conn.createStatement();resultset s= stmtNew.executeQuery(sqlstr);} catch(SQLException e1) { System.out.println(e1.getMessage()); } catch(Exception e2) { System.out.println("出错了"); }试试 按楼上大哥的方法四了一下,显示错误::[Microsoft][ODBC Microsoft Access Driver]语法错误<操作浮丢失>在查询表达式"select * from employee where employeeName =" 中 你直接String sqlstr = "select * from employee where employeeName = 'sun'";试试 String sqlstr = "select * from tb1 " ; try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); String url = "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)}; DBQ=C:/mydoc/2005cd.mdb"; Connection conn = DriverManager.getConnection(url, "", ""); System.out.println("111111111"); Statement stmtNew = conn.createStatement(); System.out.println("222222222"); ResultSet rs = stmtNew.executeQuery(sqlstr); System.out.println("555555555"); } catch(SQLException e1) { System.out.println(e1.getMessage()); } catch(Exception e2) { System.out.println("出错了"); }成功输出 :111111111222222222555555555结论,你的SQL语句有问题!!!! 按kennylee8285(康康) 大哥的方法显示错误:无效的描述器索引 import java.sql.Connection;import java.sql.DriverManager;import java.sql.ResultSet;import java.sql.SQLException;import java.sql.Statement;public class FirstAccessJdbc{ public static void main(String[] args) { Connection con = null; Statement st = null; ResultSet rs = null; try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); con = DriverManager.getConnection("jdbc:odbc:acc"); st = con.createStatement(); rs = st.executeQuery("select id, name, description from simple"); while (rs.next()) { System.out.print("id = " + rs.getLong(1)); System.out.print(" , name = " + rs.getString(2)); System.out.println(" , description = " + rs.getString(3)); } } catch (ClassNotFoundException e) { e.printStackTrace(); } catch (SQLException e) { e.printStackTrace(); } finally { try { rs.close(); } catch (Exception e1) { } try { st.close(); } catch (Exception e1) { } try { con.close(); } catch (Exception e1) { } } }} 非常感谢luoknd(飞天) 大哥(大姐),有点眉目了,不过还是不清楚为什么,下面的查询语句不对String ms = "sun";sqlstr = "select * from employee where employeeName = ms";我会尽快给分的 String sqlstr = "select * from employee";全查出来试试.......再不行要崩溃了-_- String ms = "sun";sqlstr = "select * from employee where employeeName = ms";ms是个变量,你这么放进去等于一个字符串了....... String ms = "sun";sqlstr = "select * from employee where employeeName ='+ms+'" ; String ms = "sun";sqlstr = "select * from employee where employeeName ='"+ms+"'" ; ok了,多亏了各位的帮忙,感谢luoknd(飞天),感谢各位,请接分吧 。。关于JTABLE的简单问题, 构造方法、空指针异常? 关于java的GUI对话框中父容器对象问题 如何锻炼自己的逻辑思考能力? 关于一个if语句的写法 select count(DISTINCT tr_code, tr_date) from serial_no为什么出错?? 请教一个关于面板布局方面的问题! java中的数组可不可以动态分配 新手的问题:在线等待! 请问各位大侠,java有没有提供listview控件象类似的类,若没有,如何实现 cvsnt-2.5.01和eclipse的配置问题。!! 看看这个可以实现吗
可以把sql输出来看看
很可能是查询语句的问题!
我的查询语句是:sqlstr = "select * from employee where employeeName = ms";
应该没有错误
我修改成这样:
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
string url = "jdbc:odbc:shop";
Connection conn = DriverManager.getConnection(url, "", "");
Statement stmtNew = conn.createStatement();
resultset s= stmtNew.executeQuery(sqlstr);
}
catch(SQLException e1)
{
System.out.println(e1.getMessage());
}
catch(Exception e2)
{
System.out.println("出错了");
}
shop 是我建的odbc数据源名称
结果运行过程中显示同样错误为:[Microsoft][ODBC Microsoft Access Driver]参数不足,期待是1。
String ms = "sun";
sqlstr = "select * from employee where employeeName = ms";
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
string url = "jdbc:odbc:shop";
Connection conn = DriverManager.getConnection(url, "", "");
Statement stmtNew = conn.createStatement();
resultset s= stmtNew.executeQuery(sqlstr);
}
catch(SQLException e1)
{
System.out.println(e1.getMessage());
}
catch(Exception e2)
{
System.out.println("出错了");
}
shop 是我建的odbc数据源名称
还是同样的错误,数据源的设置并没有错
sqlstr = "select * from employee where employeeName =" + ms;
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
string url = "jdbc:odbc:shop";
Connection conn = DriverManager.getConnection(url);
Statement stmtNew = conn.createStatement();
resultset s= stmtNew.executeQuery(sqlstr);
}
catch(SQLException e1)
{
System.out.println(e1.getMessage());
}
catch(Exception e2)
{
System.out.println("出错了");
}
试试
试试
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String url = "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)}; DBQ=C:/mydoc/2005cd.mdb";
Connection conn = DriverManager.getConnection(url, "", "");
System.out.println("111111111");
Statement stmtNew = conn.createStatement();
System.out.println("222222222");
ResultSet rs = stmtNew.executeQuery(sqlstr);
System.out.println("555555555");
}
catch(SQLException e1)
{
System.out.println(e1.getMessage());
}
catch(Exception e2)
{
System.out.println("出错了");
}
成功输出 :
111111111
222222222
555555555结论,你的SQL语句有问题!!!!
显示错误:无效的描述器索引
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;public class FirstAccessJdbc
{
public static void main(String[] args)
{
Connection con = null;
Statement st = null;
ResultSet rs = null;
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con = DriverManager.getConnection("jdbc:odbc:acc");
st = con.createStatement();
rs = st.executeQuery("select id, name, description from simple");
while (rs.next())
{
System.out.print("id = " + rs.getLong(1));
System.out.print(" , name = " + rs.getString(2));
System.out.println(" , description = " + rs.getString(3));
} } catch (ClassNotFoundException e)
{
e.printStackTrace();
} catch (SQLException e)
{
e.printStackTrace();
} finally
{
try
{
rs.close();
} catch (Exception e1)
{
} try
{
st.close();
} catch (Exception e1)
{
} try
{
con.close();
} catch (Exception e1)
{
}
}
}
}
不过还是不清楚为什么,下面的查询语句不对
String ms = "sun";
sqlstr = "select * from employee where employeeName = ms";我会尽快给分的
全查出来试试.......再不行要崩溃了-_-
sqlstr = "select * from employee where employeeName = ms";ms是个变量,你这么放进去等于一个字符串了.......
sqlstr = "select * from employee where employeeName ='+ms+'" ;
sqlstr = "select * from employee where employeeName ='"+ms+"'" ;