论坛登陆 注册 文章专区 投稿文章 旧版浏览
首页 | 页界资讯 | 安全动态 | 网络应用 | 组网技术 | 软件应用 | 工具软件 | 网管知识 | 帮助
文学 | 操作系统 | 注 册 表 | 编程语言 | 数 据 库 | 服 务 器 | 网页设计 | 图形图象 | VIP
论坛 | 网络安全 | 安全防范 | 黑客技术 | 硬件学堂 | 路由技术 | 搜索研究 | 站长经验 | 投稿
专题 | 教育频道 | 特色专题 | 精文荟萃 | 聊天通讯 | 网络文学 | 论坛社区 | 广告服务 | 旧版
设为首页 加入收藏
当前位置:首页>>文章>>数据库>>Oracle>>正文

JAVA连接Oracle的代码

www.xker.com 作者:不详 来源:网络转载 加入日期:2005-11-16 7:33:50
JAVA连接Oracle的代码:


 
最新做了一个连接Oracle的代码,要配好环境变量:

ClassPath=.;E:\j2sdk14\lib\tools.jar;E:\oracle\ora90\jdbc\lib\classes12.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 <host>:<port>:<sid>. 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));
}
}

上一篇:使用Oracle Wrap工具加密你的代码
下一篇:利用oradim重建Oracle服务

关闭窗口】【浏览次数:】【发送给好友】【收藏此页
相关文章 最新文章 热门文章

·妙用SSL给IIS加把锁(一)
·IIS安全保卫战
·IIS服务器组建一览 
·建站之始 始于装IIS 
·完美实现个人建站梦想 全面了解IIS组
·会计专业毕业生自荐书
·应届毕业生求职信
·个人简历表格
·Oracle里汉字长度问题
·Oracle9iAS Containers for J2EE独立
·系统优化 专题
·QQ密码丢失后能做的事情:快速找回密码
·最经典的黑客入门教材
·怎样查找对方的IP地址
·找回QQ密码的注意事项 
·实战系统虚拟利器——MS VPC 2004
·DMA让你的硬盘速度飞起来
·Dreamweaver视频教程
·电脑初学者必备之Windows进程大全
·2005年度主流聊天工具横评
评论 本站声明
【注】 发表评论必需遵守以下条例:
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款
  • 本站大部分为网络转载,如有版权问题,请通知我们,我们立即更正!

设为首页 - 版权声明 - 广告服务 - 关于我们 - 联系我们 - 友情连接
Copyright © 2003-2005 xker.com All rights reserved. 网站合作、广告联系QQ:12231446
小新技术网 冀ICP备05002857号