jdbc:类未找到异常oracle11g

时间:2015-03-17 12:22:37

标签: java sql jdbc oracle11g

import java.sql.*;
public class Sample
{
    public static void main(String[] args) throws Exception
    {
        Connection con;
        Statement st;
        ResultSet rs;
        Class.forName("oracle.jdbc.driver.OracleDriver");
        String url = "jdbc:oracle:thin:@172.16.16.50:1521:ora11g";
        String uname = "13BCS071";
        String pwd = "13BCS071";
        con = DriverManager.getConnection(url, uname, pwd);
        st = con.createStatement();
        rs = st.executeQuery("select * from LOAN");
        while(rs.next())
        {
            System.out.println(rs.getString(1) + " " + rs.getString(2) + " " + rs.getString(3));

        }
        rs.close();
        st.close();
        con.close();
    }
}

javac -cp .; ojdbc6.jar Sample.java java -cp .; ojdbc6.jar示例

我用这个执行...但得到了错误 我想检索贷款表中的信息 它有三列.. 我在贷款表中插入了许多有价值的东西 但是当试图使用java程序获取这些信息时......它不起作用...... plz..suggest我如何解决这个错误..

C:\Users\13bcs071\Desktop>dir
 Volume in drive C has no label.
 Volume Serial Number is CC03-0134

 Directory of C:\Users\13bcs071\Desktop

03/17/2015  05:28 PM    <DIR>          .
03/17/2015  05:28 PM    <DIR>          ..
03/17/2015  05:28 PM               639 Sample.java
                1 File(s)            639 bytes
               2 Dir(s)  60,961,710,080 bytes free

C:\Users\13bcs071\Desktop>javac -cp .;ojdbc6.jar Sample.java

C:\Users\13bcs071\Desktop>java -cp .;ojdbc6.jar Sample
Exception in thread "main" java.lang.ClassNotFoundException:     oracle.jdbc.driver.
OracleDriver
        at java.net.URLClassLoader$1.run(URLClassLoader.java:372)
        at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:360)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
        at java.lang.Class.forName0(Native Method)
        at java.lang.Class.forName(Class.java:259)
        at Sample.main(Sample.java:9)

0 个答案:

没有答案