2010年02月22日   头条, 码农之路   5,461 次浏览
JAVA连接不同的数据库:
1.连接Access数据库
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | public Statement getStatement() { Connection con = null; Statement state = null; String excelDriver = "jdbc:odbc:driver={Microsoft Access Driver (*.mdb)};DBQ="; String classname = "sun.jdbc.odbc.JdbcOdbcDriver"; String url = excelDriver + "D:/tracert/ip.mdb"; try { Class.forName(classname); con = DriverManager.getConnection(url); state = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (ClassNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } return state; } |
2.连接Oracle数据库
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | public Statement getStatement() { Connection con = null; Statement state = null; String name = dbp.getUserName(); String psw = dbp.getPassWord(); String ip = dbp.getServerIp(); String port = dbp.getPort(); String server = dbp.getServerName(); String url = "jdbc:oracle:thin:@" + ip + ":" + port + ":" + server; try { Class.forName("oracle.jdbc.driver.OracleDriver"); con = DriverManager.getConnection(url, name, psw); state = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY); } catch (ClassNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } return state; } |
>>> Hello World <<<
这篇内容是否帮助到你了呢?
如果你有任何疑问或有建议留给其他朋友,都可以给我留言。