Eclipse下运行java连接access的程序有问题,jdbc odbc桥接 20
程序是书上的,不能运行importjava.sql.*;publicclassExample11_1{publicstaticvoidmain(Stringargs[])...
程序是书上的,不能运行
import java.sql.*;
public class Example11_1 {
public static void main(String args[]) {
Connection con;
Statement sql;
ResultSet rs;
try{ Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}
catch(ClassNotFoundException e) {
System.out.print(e); //建立JDBC-ODBC桥接器
}
try {
con=DriverManager.getConnection("jdbc:odbc:myData","","");
sql=con.createStatement();
rs=sql.executeQuery("SELECT * FROM goods WHERE price>3000");
while(rs.next()) {
String number=rs.getString(1);
String name=rs.getString(2);
Date date=rs.getDate("madeTime");
double price=rs.getDouble("price");
System.out.println(" "+number);
System.out.println(" "+name);
System.out.println(" "+date.toString());
System.out.println(" "+price);
}
con.close();
}
catch(SQLException e) {
System.out.println(e);
}
}
}
每次运行都是java.lang.ClassNotFoundException: sun.jdbc.odbc.JdbcOdbcDriverjava.sql.SQLException: No suitable driver found for jdbc:odbc:myData
PS: shop.mdb已经建了,数据源也设定了,就是不行,是电脑缺少什么东西吗 展开
import java.sql.*;
public class Example11_1 {
public static void main(String args[]) {
Connection con;
Statement sql;
ResultSet rs;
try{ Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}
catch(ClassNotFoundException e) {
System.out.print(e); //建立JDBC-ODBC桥接器
}
try {
con=DriverManager.getConnection("jdbc:odbc:myData","","");
sql=con.createStatement();
rs=sql.executeQuery("SELECT * FROM goods WHERE price>3000");
while(rs.next()) {
String number=rs.getString(1);
String name=rs.getString(2);
Date date=rs.getDate("madeTime");
double price=rs.getDouble("price");
System.out.println(" "+number);
System.out.println(" "+name);
System.out.println(" "+date.toString());
System.out.println(" "+price);
}
con.close();
}
catch(SQLException e) {
System.out.println(e);
}
}
}
每次运行都是java.lang.ClassNotFoundException: sun.jdbc.odbc.JdbcOdbcDriverjava.sql.SQLException: No suitable driver found for jdbc:odbc:myData
PS: shop.mdb已经建了,数据源也设定了,就是不行,是电脑缺少什么东西吗 展开
2个回答
展开全部
找不到驱动类,看看你的构建路径里面是否有对应的类
如果是eclipse
ctrl+shift+T全局搜索sun.jdbc.odbc.JdbcOdbcDriver
如果没有,就配置eclipse的jdk编译环境
如果是eclipse
ctrl+shift+T全局搜索sun.jdbc.odbc.JdbcOdbcDriver
如果没有,就配置eclipse的jdk编译环境
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询