标签:none alt display gen ORC rom state 加载驱动 catch
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 }
标签:none alt display gen ORC rom state 加载驱动 catch
原文地址:https://www.cnblogs.com/yuezhihua/p/11919703.html