当前位置: 技术问答>java相关
oracle客户端环境变量设置的问题
来源: 互联网 发布时间:2015-04-16
本文导语: 安装好oracle9i客户端后,按照文档中的说明设置classpath,但是代码总是出错,代码是oracle中的demo程序。如下: import java.sql.*; //import oracle.jdbc.*; class Employee { public static void main (String args []) throws SQ...
安装好oracle9i客户端后,按照文档中的说明设置classpath,但是代码总是出错,代码是oracle中的demo程序。如下:
import java.sql.*;
//import oracle.jdbc.*;
class Employee
{
public static void main (String args [])
throws SQLException
{
// Load the Oracle JDBC driver
DriverManager.registerDriver(new oracle.jdbc.OracleDriver());
// Connect to the database
// You must put a database name after the @ sign in the connection URL.
// You can use either the fully specified SQL*net syntax or a short cut
// syntax as ::. The example uses the short cut syntax.
String url = "jdbc:oracle:thin:@172.18.8.4:1721:oracle9i";
String userName = "scott";
String password = "tiger";
if (args.length > 0) url = args[0];
if (args.length > 1) userName = args[1];
if (args.length > 2) password = args[2];
Connection conn =
DriverManager.getConnection (url, userName, password);
// Create a Statement
Statement stmt = conn.createStatement ();
// Select the ENAME column from the EMP table
ResultSet rset = stmt.executeQuery ("select * from eddie_fee");
// Iterate through the result and print the employee names
while (rset.next ())
System.out.println (rset.getString (1));
}
}
编译时出现错误在
DriverManager.registerDriver(new oracle.jdbc.OracleDriver());
行
import java.sql.*;
//import oracle.jdbc.*;
class Employee
{
public static void main (String args [])
throws SQLException
{
// Load the Oracle JDBC driver
DriverManager.registerDriver(new oracle.jdbc.OracleDriver());
// Connect to the database
// You must put a database name after the @ sign in the connection URL.
// You can use either the fully specified SQL*net syntax or a short cut
// syntax as ::. The example uses the short cut syntax.
String url = "jdbc:oracle:thin:@172.18.8.4:1721:oracle9i";
String userName = "scott";
String password = "tiger";
if (args.length > 0) url = args[0];
if (args.length > 1) userName = args[1];
if (args.length > 2) password = args[2];
Connection conn =
DriverManager.getConnection (url, userName, password);
// Create a Statement
Statement stmt = conn.createStatement ();
// Select the ENAME column from the EMP table
ResultSet rset = stmt.executeQuery ("select * from eddie_fee");
// Iterate through the result and print the employee names
while (rset.next ())
System.out.println (rset.getString (1));
}
}
编译时出现错误在
DriverManager.registerDriver(new oracle.jdbc.OracleDriver());
行
|
"//import oracle.jdbc.*; "
为何要注释掉这个包?
应该import进来.
为何要注释掉这个包?
应该import进来.
|
同样的程序,同样是ORA9I,我在jdk1.4下一步运行通过...
oracle9i安装目录jdbc子目录下的class12.jar要加到classpath环境变量中
1.cmd
2.javac Employee.java
|
1、安装jre后不要设置环境变量(classpath etc.)
2、运行时使用 java -classpath XXXX
2、运行时使用 java -classpath XXXX
|
靠! TechnoFantasy(www.applevb.com) 你上次提的问题还没给分呢
我服了你了
我服了你了
|
haha
|
哈哈!要分心切了点,不过结贴时一分不给无所谓,您老到也发个言呀.