您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

JAVA连接Oracle的代码

2025/12/16 23:43:19发布26次查看
最新做了一个连接oracle的代码,要配好环境变量: classpath=.;e:j2sdk14lib ools.jar;e:oracleora90jdbclibclasses12.zip 测试的电脑已经装好oracle客户端,而且用sqlplus可以连接上。 /* * this sample shows how to list all the names from the emp tabl
最新做了一个连接oracle的代码,要配好环境变量: classpath=.;e:j2sdk14lib ools.jar;e:oracleora90jdbclibclasses12.zip
测试的电脑已经装好oracle客户端,,而且用sqlplus可以连接上。
/*
* this sample shows how to list all the names from the emp table
*
* it uses the jdbc thin driver. see the same program in the
* oci8 samples directory to see how to use the other drivers.
*/ // you need to import the java.sql package to use jdbc
import java.sql.*; class test
{
public static void main (string args [])
throws sqlexception
{
// load the oracle jdbc driver
drivermanager.registerdriver(new oracle.jdbc.oracledriver());
/* try{
class.forname(oracle.jdbc.driver.oracledriver);
}catch(exception e){
system.out.println(no driver!);
}
*/
// 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.28.31.85:1521:yikatong;
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];
system.out.println(url);
system.out.println(username);
system.out.println(password);
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 test); // iterate through the result and print the employee names
while (rset.next ())
system.out.println (rset.getstring (1));
}
}
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product