我正在尝试使用jdbc通过java打印employees表的内容。 我用ref cursor创建了以下包和函数。
create or replace
package packagename as
type ref_cursor is ref cursor;
end;
/
create or replace function get_employees
return packagename.ref_cursor
as employees_cursor packagename.ref_cursor;
begin
open employees_cursor for
select * from employees;
return employees_cursor;
end;
/
我的java代码如下:
import java.sql.*;
import oracle.jdbc.*;
import java.math.*;
import java.io.*;
import java.awt.*;
import oracle.jdbc.pool.OracleDataSource;
public class getemployees {
public static void main (String args []) throws SQLException {
try
{
//Connecting to Oracle server
OracleDataSource ds = new oracle.jdbc.pool.OracleDataSource();
ds.setURL("jdbc:oracle:thin:@castor.cc.fsu.edu:1521:acad111");
Connection conn = ds.getConnection("xxxxxxxx", "xxxxxxxx");
//Prepare to call stored procedure:
CallableStatement cs = conn.prepareCall("begin ? := packagename.get_employees(); end;");
//register the out parameter (the first parameter)
cs.registerOutParameter(1, OracleTypes.CURSOR);
// execute and retrieve the result set
cs.execute();
ResultSet rs = (ResultSet)cs.getObject(1);
// print the results
while (rs.next()) {
System.out.println(rs.getString(1) + "\t" +
rs.getString(2) + "\t" + rs.getString(3));
}
//close the result set, statement, and the connection
cs.close();
conn.close();
}
catch (SQLException ex) { System.out.println ("\n*** SQLException caught ***\n" + ex.getMessage());}
catch (Exception e) {System.out.println ("\n*** other Exception caught ***\n");}
}
}
关于compliling我没有错误但是当我运行它时我得到以下内容:
fsu% javac -cp "ojdbc6.jar" getemployees.java
fsu% java getemployees
Exception in thread "main" java.lang.NoClassDefFoundError: oracle/jdbc/pool/OracleDataSource
at getemployees.main(getemployees.java:18)
Caused by: java.lang.ClassNotFoundException: oracle.jdbc.pool.OracleDataSource
at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
... 1 more
我没有任何Java经验,我做错了什么?