包oracle.jdbc不存在导入oracle.jdbc

时间:2012-04-27 19:04:43

标签: java import jar jcreator

我有 WinXP Pro SP3,Oracle Xpress 11g,Sqlplus 11.2.0.2.0生产和JDK 1.6.0

编辑 :JCreator

在我的PC系统属性环境中,我有:

CLASSPATH

.;C:\mylib\*

路径

C:\oraclexe\app\oracle\product\11.2.0\server\bin;C:\Program Files\Java\jdk1.6.0_06;C:\php;C:\mylib\*

在C:\ mylib里面我有: ojdbc6.jar

我使用Sqlplus创建了表,我的数据库运行。 但连接没有运气 错误:

G:\src\Database.java:16:
package oracle.jdbc does not exist
import oracle.jdbc.*;
^
java.lang.NoClassDefFoundError: Database
Caused by: java.lang.ClassNotFoundException: Database
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:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:276)
at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
Exception in thread "main"

源代码,Database.java:

import java.sql.*;
import java.sql.Connection;

public class Database {

    static Connection con = null;

    public Database() {
    }

    public static Connection getConnection() throws SQLException, ClassNotFoundException {

        try {
            Class.forName("oracle.jdbc.OracleDriver");

            con = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:XE", "system", "1234");

        } catch (Exception e) {
            System.err.println("Exception: " + e.getMessage());
        }

        return con;
    }

    public static void closeConnection() {
        try {
            con.close();
            con = null;
            System.out.println("Disconnected from database ....");
        } catch (SQLException ex) {
        }
    }
} // END CLASS

嗯 我想我需要将jar文件导入我的Databsa.java文件。 我该怎么做?

当我从Oracle演示示例中运行JdbcCheckup.java时,我得到:

E:\Downloads\Demo\samples\generic\JdbcCheckup.java:15: package oracle.jdbc.pool does not exist
import oracle.jdbc.pool.OracleDataSource;
^
E:\Downloads\Demo\samples\generic\JdbcCheckup.java:40: cannot find symbol
symbol : class OracleDataSource
location: class JdbcCheckup
OracleDataSource ods = new OracleDataSource();
^
E:\Downloads\Demo\samples\generic\JdbcCheckup.java:40: cannot find symbol
symbol : class OracleDataSource
location: class JdbcCheckup
OracleDataSource ods = new OracleDataSource();
^
java.lang.NoClassDefFoundError: JdbcCheckup
> Caused by: java.lang.ClassNotFoundException: JdbcCheckup
> 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:306)
> at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:276)
> at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
> at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
> Exception in thread "main"
> Process completed.

0 个答案:

没有答案