文件名称:jdbc连接oracle
文件大小:783B
文件格式:JAVA
更新时间:2015-03-20 07:15:48
jdbc连接oracle
package com.util; import java.sql.Connection; import java.sql.DriverManager; import java.sql.SQLException; public class DB { private static Connection conn; private static String url="jdbc:oracle:thin:@127.0.0.1:1521:databasename"; private static String uname="username"; private static String passwd="password"; static{ try { Class.forName("oracle.jdbc.OracleDriver"); } catch (ClassNotFoundException e) { e.printStackTrace(); } } public static Connection getconn() { if (conn==null) { try { conn=DriverManager.getConnection(url,uname,passwd); } catch (SQLException e) { e.printStackTrace(); } } return conn; } public static void main(String[] args) { System.err.println(new DB().getconn()); } }