编译出错,错误信息:"DB.java": Error #: 302 : cannot access class oracle.jdbc.OracleDriver; java.io.IOException: class not found: class oracle.jdbc.OracleDriver at line 30, column 48
我在\控制面板\系统中编辑Classpath中增加路径为D:\j2sdkee\lib\system\classes12.zip但还是不对 错误如下,请予回答,本人急于解决此问题,谢谢! "DB.java": Error #: 704 : cannot access directory oracle\jdbc at line 8, column 1 "DB.java": Error #: 302 : cannot access class oracle.jdbc.OracleDriver; java.io.IOException: class not found: class oracle.jdbc.OracleDriver at line 34, column 48 "DB.java": Error #: 300 : variable conn not found in class DB.DB at line 38, column 7 "DB.java": Error #: 300 : variable conn not found in class DB.DB at line 39, column 23
Oracle816客户端程序:http://10.141.185.185/web/sheepblack/study/oracle/oracle816classes12b.zip 连接方法范例: import java.sql.*;class Employee { public static void main (String args []) throws SQLException, ClassNotFoundException { // Load the Oracle JDBC driver Class.forName ("oracle.jdbc.driver.OracleDriver"); // Connect to the database // You can put a database name after the @ sign in the connection URL. Connection conn = DriverManager.getConnection ("jdbc:oracle:oci8:@", "scott", "tiger"); // Create a Statement Statement stmt = conn.createStatement (); // Select the ENAME column from the EMP table ResultSet rset = stmt.executeQuery ("select ENAME from EMP"); // Iterate through the result and print the employee names while (rset.next ()) System.out.println (rset.getString (1)); } }
Oracle816客户端程序:http://10.141.185.185/web/sheepblack/study/oracle/oracle816classes12b.zip 连接方法范例: import java.sql.*;class Employee { public static void main (String args []) throws SQLException, ClassNotFoundException { // Load the Oracle JDBC driver Class.forName ("oracle.jdbc.driver.OracleDriver"); // Connect to the database // You can put a database name after the @ sign in the connection URL. Connection conn = DriverManager.getConnection ("jdbc:oracle:oci8:@", "scott", "tiger"); // Create a Statement Statement stmt = conn.createStatement (); // Select the ENAME column from the EMP table ResultSet rset = stmt.executeQuery ("select ENAME from EMP"); // Iterate through the result and print the employee names while (rset.next ()) System.out.println (rset.getString (1)); } }
//------------------------------------------------------------------
import java.sql.*;
import oracle.jdbc.*;public ResultSet GetQuery()
throws SQLException
{
DriverManager.registerDriver(new oracle.jdbc.OracleDriver());
String url = "jdbc:oracle:thin:@192.18.8.4:1521:ORCL";
String userName = "SCOTT";
String password = "TIGER";
String SQL = "SELECT * FROM EMP";
Connection conn = DriverManager.getConnection (url, userName, password);
Statement cstmt = conn.createStatement();
ResultSet rs = cstmt.executeQuery(SQL);
return rs;
}
//------------------------------------------------------------------如果你还有什么疑问,再来。 :-)
import java.util.Hashtable;import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.sql.DataSource;/**
* 建立与数据源的连接
* 用法ConnectionFactory.getConnection()
* 注意:调用以后一定要close掉Connection,否则连接池会满
*/
public class ConnectionFactory { //该类自已的一个静态实例
private static ConnectionFactory factorySingleton; //存储DataSource
private DataSource dataStore = null; //上下文联系
private Context ctx; /*
* 内部静态构造
*/
private ConnectionFactory() throws NamingException{
} /*
* 建立与数据源的连接, 目前只实用于Weblogic
* 服务器名要在内部指定.
*/
private Connection createConnection() throws NamingException{
Connection conn = null;
ctx = null;
Hashtable ht = new Hashtable(); ht.put(ctx.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory");
ht.put(ctx.PROVIDER_URL, "t3://172.21.70.1:7001"); if (dataStore==null) {
try {
ctx = new InitialContext(ht);
dataStore = (javax.sql.DataSource)ctx.lookup("mrpSource");
}catch (Exception e) {
System.out.println(e.getMessage());
}
} try {
conn = dataStore.getConnection();
}catch(Exception e) {
e.printStackTrace();
}
return conn;
} /**
* 获取ConnectionFactory自身的一个实例, 不存在的话,则建立一个.
*/
public static Connection getConnection() throws NamingException{
if (ConnectionFactory.factorySingleton == null) {
ConnectionFactory.factorySingleton = new ConnectionFactory();
} return ConnectionFactory.factorySingleton.createConnection();
}}
此处语句错误,提示为不能直接访问该目录oralce;cannot access directory oracle,且我在服务启动时j2ee下的config下配置相应的属性,但我并不知该这个配置是否能调入,谢谢!
CLASSPATH中加入:$ORACLE_HOME/jdbc/lib/classes/classes12.zip;再试试~!! :-}
错误如下,请予回答,本人急于解决此问题,谢谢!
"DB.java": Error #: 704 : cannot access directory oracle\jdbc at line 8, column 1
"DB.java": Error #: 302 : cannot access class oracle.jdbc.OracleDriver; java.io.IOException: class not found: class oracle.jdbc.OracleDriver at line 34, column 48
"DB.java": Error #: 300 : variable conn not found in class DB.DB at line 38, column 7
"DB.java": Error #: 300 : variable conn not found in class DB.DB at line 39, column 23
连接方法范例:
import java.sql.*;class Employee
{
public static void main (String args [])
throws SQLException, ClassNotFoundException
{
// Load the Oracle JDBC driver
Class.forName ("oracle.jdbc.driver.OracleDriver"); // Connect to the database
// You can put a database name after the @ sign in the connection URL.
Connection conn =
DriverManager.getConnection ("jdbc:oracle:oci8:@", "scott", "tiger"); // Create a Statement
Statement stmt = conn.createStatement (); // Select the ENAME column from the EMP table
ResultSet rset = stmt.executeQuery ("select ENAME from EMP"); // Iterate through the result and print the employee names
while (rset.next ())
System.out.println (rset.getString (1));
}
}
连接方法范例:
import java.sql.*;class Employee
{
public static void main (String args [])
throws SQLException, ClassNotFoundException
{
// Load the Oracle JDBC driver
Class.forName ("oracle.jdbc.driver.OracleDriver"); // Connect to the database
// You can put a database name after the @ sign in the connection URL.
Connection conn =
DriverManager.getConnection ("jdbc:oracle:oci8:@", "scott", "tiger"); // Create a Statement
Statement stmt = conn.createStatement (); // Select the ENAME column from the EMP table
ResultSet rset = stmt.executeQuery ("select ENAME from EMP"); // Iterate through the result and print the employee names
while (rset.next ())
System.out.println (rset.getString (1));
}
}
添加DATASOURCE,并在DATASOURCE里面说明JDBC和SERVER、PORT。
具体做法使用一下deploytool就比较清楚了。