首页 > 数据库技术 > 详细

java链接oracle数据库

时间:2019-11-23 21:43:03      阅读:76      评论:0      收藏:0      [点我收藏+]
技术分享图片
 1 package csu.lys.com;
 2 
 3 import java.sql.Connection;
 4 import java.sql.DriverManager;
 5 import java.sql.ResultSet;
 6 import java.sql.SQLException;
 7 import java.sql.Statement;
 8 import java.util.Hashtable;
 9 
10 import javax.sql.StatementEvent;
11 
12 public class ConnOracle {
13 
14     /**
15      * @param args
16      */
17     public static void main(String[] args) {
18         // TODO Auto-generated method stub
19         //加载驱动
20         String oracleDriverString = "oracle.jdbc.driver.OracleDriver";
21         Hashtable<String, User> ht = new Hashtable<String, User>();
22         try {
23             //加载驱动
24             Class.forName(oracleDriverString);
25             //得到链接
26             Connection ct = DriverManager.getConnection("jdbc:oracle:thin:@127.0.0.1:1521:ORCLLYS", "SCOTT", "TIGER");
27             //创建statement
28             Statement statement = ct.createStatement();
29             //查询
30             ResultSet resultSet = statement.executeQuery("select * from users");
31             
32             if(resultSet.next()){
33                 int id = resultSet.getInt(1);
34                 String name = resultSet.getString(2);
35                 String passwd = resultSet.getString(3);
36                 User user = new User(id, name, passwd);
37                 ht.put("lys", user);
38             }
39             
40         } catch (Exception e) {
41             // TODO Auto-generated catch block
42             e.printStackTrace();
43         }
44         System.out.println(ht.get("lys").toString());
45 
46     }
47 
48 }
View Code

 

java链接oracle数据库

原文:https://www.cnblogs.com/yuezhihua/p/11919703.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!