代码是按照网上写的:
package hwr.demo.example;
import java.sql.*;
public class ConnectDB {
public ConnectDB() {
// TODO Auto-generated constructor stub
}
public static void main(String[] args) {
// TODO Auto-generated method stub
// DriverManager.registerDriver(new oracle.jdbc.OracleDriver());
try {
Class.forName("oracle.jdbc.OracleDriver");
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
String url = "jdbc:oracle:thin:@localhost:1521:hwr";
String userName = "scott";
String password = "tiger";
try {
// OracleDataSource dataSource = new OracleDataSource();
Connection conn = DriverManager.getConnection(url, userName, password);
Statement stmt = conn.createStatement();
ResultSet res = stmt.executeQuery("select * from dept");
while (res.next()){
System.out.println(res.getString(1));
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
在win7下,oracle10,为什么我在build path已经导入了了classes12.jar文件,也配置了环境变量(C:\oracle\product\10.2.0\db_1\jdbc\lib\classes12.zip;),为什么它还是没有jdbc包的???DriverManager.registerDriver(new oracle.jdbc.OracleDriver());这句话会有语法错误,因为oracle.的时候是没有jdbc出现的。而且会出现以下错误:(希望大牛指点)
java.lang.ClassNotFoundException: oracle.jdbc.OracleDriver
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at hwr.demo.example.ConnectDB.main(ConnectDB.java:18)
java.sql.SQLException: No suitable driver found for jdbc:oracle:thin:@localhost:1521:hwr
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at hwr.demo.example.ConnectDB.main(ConnectDB.java:40)
oracle java jdbc thin
------解决方案--------------------
代码没问题,应该是包的问题哦。
------解决方案--------------------
ojdbc14的jar包,构建路径中导入就可以了
------解决方案--------------------
和jdk版本一关系不大,主要是和数据库的版本
jdk1.5/jdk1.6 + ojdbc14/ojdbc5