- 论坛徽章:
- 0
|
请教大神,连接 11g出错,将ojdbc6.jar从oracle安装目录下拷贝到JRE的lib目录下,依然连接不上。- import java.sql.*;
- public class TestOracle {
- public static void main(String[] args) {
- try{
- Class.forName("oracle.jdbc.driver.OracleDriver");
- Connection conn = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:orcl", "scott", "tiger");
- Statement stmt = conn.createStatement();
- ResultSet rs = stmt.executeQuery("select (1+1) as math from dual;");
- while(rs.next()){
- System.out.println(rs.getInt(1) + "\t" + rs.getString(2));
- }
- }catch(Exception err){
- System.out.println(err.toString());
- err.printStackTrace();
- }
- }
- }
复制代码 用javac编译时,没有提示错误。但,运行时:
- java TestOracle
- java.lang.ClassNotFoundException: oracle.jdbc.driver.OracleDriver
- java.lang.ClassNotFoundException: oracle.jdbc.driver.OracleDriver
- at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
- at java.security.AccessController.doPrivileged(Native Method)
- at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
- at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
- at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
- at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
- at java.lang.Class.forName0(Native Method)
- at java.lang.Class.forName(Class.java:169)
- at TestOracle.main(TestOracle.java:7)
复制代码 |
|