eclipse中編譯出錯
package?demo.utils; import?java.sql.Connection; import?java.sql.DriverManager; import?java.sql.ResultSet; import?java.sql.SQLException; import?java.sql.Statement; public?class?JDBCUtils?{ ?????public?static?String?driver?="oracle.jdbc.oracleDriver"; ?????public?static?String?url="jdbc:oracle:thin:@localhost:ocrl"; ?????public?static?String?user="scott"; ?????public?static?String?passworld="tiger"; ????? ?????//注冊數(shù)據(jù)庫驅(qū)動 ?????static?{ ???? ?try?{ Class.forName(driver); //?DriverManager.registerDriver(driver); }?catch?(ClassNotFoundException?e)?{ //?TODO?Auto-generated?catch?block e.printStackTrace(); throw?new?ExceptionInInitializerError(e); } ?????} ????//獲取數(shù)據(jù)庫連接 ?????public?static?Connection?getConnection(){ ???? ????try?{ return?DriverManager.getConnection(url,?user,?passworld); }?catch?(SQLException?e)?{ //?TODO?Auto-generated?catch?block e.printStackTrace(); } ???? ????return?null; ?????} ?????//釋放數(shù)據(jù)庫資源 ?????public?static?void?release(Connection?conn,Statement?call,ResultSet?rt){ ???? ?if(rt!=null){ ???? ?try?{ rt.close(); }?catch?(SQLException?e)?{ //?TODO?Auto-generated?catch?block e.printStackTrace(); }finally{ rt=null; } ???? ?if?(call!=null){ ???? ??try?{ ((Connection)?call).close(); }?catch?(SQLException?e)?{ //?TODO?Auto-generated?catch?block e.printStackTrace(); }finally{ call=null; } ???? ?} ???? ?if?(conn!=null){ ???? ?try?{ conn.close(); }?catch?(SQLException?e)?{ //?TODO?Auto-generated?catch?block e.printStackTrace(); }finally{ conn=null; } ???? ?} ???? ?} ?????} } package?demo.oracle; import?java.sql.CallableStatement; import?java.sql.Connection; import?org.junit.Test; import?demo.utils.JDBCUtils; import?oracle.jdbc.internal.OracleTypes; public?class?TestFunction?{ @Test ??????public?void??testFunction(){ ???? ?????String?sql="?call?qureyempincome(?)"; ???? ??????Connection??conn=null; ???? ??????CallableStatement?call=null; ???? ??????try?{ ???? ???? //得到數(shù)據(jù)庫鏈接 ???? ???? ??conn=JDBCUtils.getConnection(); ???? ???? //基于鏈接創(chuàng)建statement ???? ???? ??call=conn.prepareCall(sql); ???? ???? ??//對于輸出參數(shù)?申明 ???? ???? ??call.registerOutParameter(1,OracleTypes.NUMBER); ???? ???? ??//?對于輸入?yún)?shù)?賦值? ???? ???? ??call.setInt(2,?7839); ???? ???? ??//執(zhí)行調(diào)用 ???? ???? ??call.execute(); ???? ???? ??//取年收入的結(jié)果輸出 ???? ???? ??double?income?=call.getDouble(1); ???? ???? ??System.out.println("該員工的年收入是:"+income); ???? ??????}catch(Exception?e){ ???? ???? ??e.printStackTrace(); ???? ??????}finally{ ???? ???? ??JDBCUtils.release(conn,?call,?null); ???? ??????} ??????} }
java.lang.ClassNotFoundException: oracle.jdbc.oracleDriver
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:264)
at demo.utils.JDBCUtils.<clinit>(JDBCUtils.java:20)
at demo.oracle.TestFunction.testFunction(TestFunction.java:19)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)
2017-08-29
driver類是Oracle.jdbc.driver.OracleDriver注意區(qū)別大小寫,然后就是環(huán)境變量以及驅(qū)動、數(shù)據(jù)庫版本問題。
2017-08-30
好的,謝謝