連接Oracle數據庫幫助類,就是把連接Oracle數據庫的方法封裝起來,只需要在其它頁面調用就可,不需要重復寫。
import java.sql.Connection; import java.sql.DriverManager; import java.sql.SQLException; import oracle.jdbc.driver.OracleDriver; /** * 數據庫連接幫助類 * @author zql_pc * */ public class DbHelp { /* * 數據庫連接 */ public static Connection lianjie(){ //數據庫配置 String driver = "oracle.jdbc.driver.OracleDriver";//驅動 String url = "jdbc:oracle:thin:@localhost:1521:JBITDB"; String user = "epet"; String pwd = "123456"; try { //第一步:加載驅動 Class.forName(driver);// -->反射 Connection conn = DriverManager.getConnection(url,user,pwd); return conn; } catch (ClassNotFoundException e) { e.printStackTrace(); } catch (SQLException e) { e.printStackTrace(); } return null;
}
}