標籤:catch ini break ret led except 串連池 lte user
import java.beans.PropertyVetoException;import java.sql.Connection;import java.sql.SQLException;import javax.sql.ConnectionPoolDataSource;import javax.swing.text.DefaultEditorKit.InsertBreakAction;import com.mchange.v2.c3p0.ComboPooledDataSource;public class ConnectData { public static void main(String[] args) { System.out.println(ConnectData.getConnection()); } private static String userName="LF"; private static String password="LF"; public static Connection getConnection() { //建立串連池 ComboPooledDataSource dataSource = new ComboPooledDataSource(); //通過映射來驅動 try { dataSource.setDriverClass("oracle.jdbc.driver.OracleDriver"); } catch (PropertyVetoException e) { e.printStackTrace(); } //設定url dataSource.setJdbcUrl("jdbc:oracle:thin:@192.168.10.105:1521:orcl"); //設定資料庫使用者帳號 dataSource.setUser(userName); //設定資料庫密碼 dataSource.setPassword(password); dataSource.setInitialPoolSize(5); dataSource.setMaxPoolSize(13); dataSource.setMinPoolSize(3); try { // 擷取串連 return dataSource.getConnection(); } catch (SQLException e) { e.printStackTrace(); } return null; }}
Java c3p0串連池