jdbc连接gp单例模式
抽象
这是常见数据库的JDBC连接的快速参考。 我似乎必须大量查找此信息,因此我认为最好将所有参考资料放在一个地方。
德比
<dependency><groupId>org.apache.derby</groupId><artifactId>derbyclient</artifactId><version>10.11.1.1</version><scope>test</scope>
</dependency>
<dependency><groupId>org.apache.derby</groupId><artifactId>derby</artifactId><version>10.11.1.1</version><scope>test</scope>
</dependency>
嵌入式(内存中)
Class.forName("org.apache.derby.jdbc.EmbeddedDriver");String connectionUrl= "jdbc:derby:C:/My Databases/Derby/Test;user=;password=;create=true";Connection conn= DriverManager.getConnection(connectionUrl);
远程
Class.forName("org.apache.derby.jdbc.ClientDriver");String connectionUrl= "jdbc:derby://localhost:1527/widget";String user = "sa";
String pass = "sa";Connection conn= DriverManager.getConnection(connectionUrl, user, pass);
PostgeSQL
<dependency><groupId>org.postgresql</groupId><artifactId>postgresql</artifactId><version>42.1.4.jre7</version><scope>test</scope>
</dependency>
Class.forName("org.postgresql.Driver");String connectionUrl= "jdbc:postgresql://localhost:5432/widget";String user = "widgetapp";
String pass = "widgetapp";Connection conn= DriverManager.getConnection(connectionUrl, user, pass);
Oracle
从http://www.oracle.com/technetwork/database/features/jdbc/index.html下载JDBC驱动程序
<dependency><groupId>com.oracle</groupId><artifactId>ojdbc6</artifactId><version>11.2.0.4</version><scope>system</scope><systemPath>${basedir}/lib/ojdbc6.jar</systemPath>
</dependency>
Class.forName("oracle.jdbc.driver.OracleDriver");String SID= "xe";String connectionUrl= "jdbc:oracle:thin:@localhost:1521:" + SID;String user = "hr";
String pass = "hr";Connection conn= DriverManager.getConnection(connectionUrl, user, pass);
摘要
就是这样...享受!
翻译自: https://www.javacodegeeks.com/2018/01/jdbc-connections-cheat-sheet.html
jdbc连接gp单例模式