Driven part of the database connection code

2011-02-21  来源:本站原创  分类:Database  人气:119 

First, the connection Oracle8/8i/9i database (with thin mode)

Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();
String url="jdbc:oracle:thin:@localhost:1521:orcl";
//orcl For your database SID
String user="scott";
String password="tiger";
Connection conn= DriverManager.getConnection(url,user,password);
Statement stmt=conn.createStatement

Second, the database connection Sql Server7.0/2000

Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance();
String url="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=pubs";
//pubs For your database
String user="sa";
String password="";
Connection conn= DriverManager.getConnection(url,user,password);
Statement stmt=conn.createStatement

Third, to connect DB2 database

Class.forName("com.ibm.db2.jdbc.app.DB2Driver ").newInstance();
String url="jdbc:db2://localhost:5000/sample";
//sample For your database name
String user="admin";
String password="";
Connection conn= DriverManager.getConnection(url,user,password);
Statement stmt=conn.createStatement

Fourth, the Informix database connection

Class.forName("com.informix.jdbc.IfxDriver").newInstance();
String url =
"jdbc:informix-sqli://123.45.67.89:1533/testDB:INFORMIXSERVER=myserver;
user=testuser;password=testpassword";
//testDB For your database name
Connection conn= DriverManager.getConnection(url);
Statement stmt=conn.createStatement

Fifth, Sybase database connection

Class.forName("com.sybase.jdbc.SybDriver").newInstance();
String url =" jdbc:sybase:Tds:localhost:5007/tsdata";
//tsdata For your database name
Properties sysProps = System.getProperties();
SysProps.put("user","userid");
SysProps.put("password","user_password");
Connection conn= DriverManager.getConnection(url, SysProps);
Statement stmt=conn.createStatement

Sixth, to connect to MySQL database

Class.forName("org.gjt.mm.mysql.Driver").newInstance();
String url ="jdbc:mysql://localhost/softforum?    

user=soft&password=soft1234&useUnicode=true&characterEncoding=8859_1"
//testDB For your database name
Connection conn= DriverManager.getConnection(url);
Statement stmt=conn.createStatement

Seven, PostgreSQL database connection

Class.forName("org.postgresql.Driver").newInstance();
String url ="jdbc:postgresql://localhost/soft"
//soft For your database name
String user="myuser";
String password="mypassword";
Connection conn= DriverManager.getConnection(url,user,password);
Statement stmt=conn.createStatement

========================== ======================= Quote =====

1. MySQL(http://www.mysql.com)mm.mysql-2.0.2-bin.jar
Class.forName( "org.gjt.mm.mysql.Driver" );
cn = DriverManager.getConnection( "jdbc:mysql://MyDbComputerNameOrIP:3306/myDatabaseName", sUsr, sPwd ); 

2. PostgreSQL(http://www.de.postgresql.org)pgjdbc2.jar
Class.forName( "org.postgresql.Driver" );
cn = DriverManager.getConnection( "jdbc:postgresql://MyDbComputerNameOrIP/myDatabaseName", sUsr, sPwd ); 

3. Oracle(http://www.oracle.com/ip/deploy/database/oracle9i/)classes12.zip
Class.forName( "oracle.jdbc.driver.OracleDriver" );
cn = DriverManager.getConnection( "jdbc:oracle:thin:@MyDbComputerNameOrIP:1521:ORCL", sUsr, sPwd ); 

4. Sybase(http://jtds.sourceforge.net)jconn2.jar
Class.forName( "com.sybase.jdbc2.jdbc.SybDriver" );
cn = DriverManager.getConnection( "jdbc:sybase:Tds:MyDbComputerNameOrIP:2638", sUsr, sPwd );
// (Default-Username/Password: "dba"/"sql") 

5. Microsoft SQLServer(http://jtds.sourceforge.net)
Class.forName( "net.sourceforge.jtds.jdbc.Driver" );
cn = DriverManager.getConnection( "jdbc:jtds:sqlserver://MyDbComputerNameOrIP:1433/master", sUsr, sPwd ); 

6. Microsoft SQLServer(http://www.microsoft.com)
Class.forName( "com.microsoft.jdbc.sqlserver.SQLServerDriver" );
cn = DriverManager.getConnection( "jdbc:microsoft:sqlserver://MyDbComputerNameOrIP:1433;databaseName=master", sUsr, sPwd ); 

7. ODBC
Class.forName( "sun.jdbc.odbc.JdbcOdbcDriver" );
Connection cn = DriverManager.getConnection( "jdbc:odbc:" + sDsn, sUsr, sPwd ); 

8.DB2
Class.forName("Com.ibm.db2.jdbc.net.DB2Driver");
String url="jdbc:db2://192.9.200.108:6789/SAMPLE"
cn = DriverManager.getConnection( url, sUsr, sPwd );
相关文章
  • Driven part of the database connection code 2011-02-21

    First, the connection Oracle8/8i/9i database (with thin mode) Class.forName("oracle.jdbc.driver.OracleDriver").newInstance(); String url="jdbc:oracle:thin:@localhost:1521:orcl"; //orcl For your database SID String user="scott"

  • Test database connection code 2011-08-07

    These codes are tested, no problem 1 MySql database connection public class TestMySqlConnection { public static void main(String[] srg) throws SQLException { String driverName = "com.mysql.jdbc.Driver"; // Load the JDBC driver String dbURL = &qu

  • mysql sql server 2000/2008 oracle10g database connection code 2011-08-07

    These codes are tested, no problem 1 MySql database connection public class TestMySqlConnection { public static void main(String[] srg) throws SQLException { String driverName = "com.mysql.jdbc.Driver"; // Loading JDBC driver String dbURL = &quo

  • php mysql database connection code to connect database operation code _php 2010-04-06

    <?php mysql_connect("localhost","root","123456") // Fill out the MySQL username and password or die("Could not connect to MySQL server!"); mysql_select_db("phpcms") // The database name or die("Cou

  • JDBC database connection principle 2011-01-18

    JDBC database connection: Java Database Connectivity, (Java Database Connectivity, referred to as JDBC) is used to standardize the Java language client how to access the database application program interface, provides such data in the database query

  • The basic principles of database connection pool 2010-06-11

    Traditional database connection (refer to the basic realization through DriverManager and DataSource to connect), a database connection objects are corresponding to a physical database connection, database connection and the closure of the establishm

  • C # connection Access.SQL Server.Oracle.MySQL.DB2 and SyBase six different database source code 2010-06-17

    This article lists the C # to connect Access, SQL Server, Oracle, MySQL, DB2 and SyBase six different database programs and the need to pay attention to the point source. 1.C # Connection Access Code: using System.Data; using System.Data.OleDb; strin

  • Asp.net database connection class and common class, method code 2010-04-15

    using System; using System.Collections; using System.ComponentModel; using System.Data; using System.Data.SqlClient; using System.Drawing; using System.Web; using System.Web.SessionState; using System.Web.UI; using System.Web.UI.HtmlControls; using S

  • Java MySQL database connection 2011-09-30

    MySQL connections in PHP is the easiest, PHP with a MySQL distribution package is usually driven modules, simply modify the PHP configuration file you can load the MySQL driver, and PHP provides a lot of special functions in the MySQL database operat

  • SqlServer database connection pool to connect tomcat 2009-03-01

    First, install the JDBC Driver The database driver jar file to put (Tomcat_install) \ common \ lib directory Second, configure the Connection Pool 1. Overall connection pool configuration, Tomcat in any Web application can be configured to use the co

  • JDBC technology and database connection pooling feature (reprint) 2009-10-02

    JDBC Basics First, access the database using JDBC basic steps: A. loading JDBC driver B. definition connection URL C. establish a connection D. create a Statement object E. execute a query or update F. The results dealing with G. Close the connection

  • Set the database connection pool BoneCP 2010-03-29

    Why should we do with the database connection pool? Ground to online search, the basic principles of a lot of code is a lot, because of his right asp.net Bijiao Shu, java is started, a little health, so much trouble to write their own, so that a web

  • Why do you want to add a database connection pool 2010-04-27

    Today in learning kauklahti when he wrote a Jdbc connection mysql example. Be regarded as a bit Jdbc usage review. The entire source code examples are as follows: //------------------------------------------------------------------------------------

  • There is a relatively easy way to track which does not release database connection 2009-06-03

    There is a relatively easy way to track which database connection is not released, is to do a proxy class, the proxy class that they have a time-out mechanisms, timed out do not print the call stack is released package com.poweroa.jdbc; import java.s

  • JAVA Database Connection Daquan 2009-01-15

    Database Connectivity (JDBC) from a group with the Java programming language classes and interfaces. JDBC for tool / database developers with a standard API, so that they can use a pure Java API to write database applications. However, each developer

  • [Change] the use of JAVA in the dynamic proxy to achieve database connection pooling 2010-03-22

    Database connection pool in the preparation of applications often need to use the module, too frequent in terms of connecting to the database on the service performance is a bottleneck, the use of buffer pool technology to eliminate this bottleneck.

  • Weblogic access oracle database connection pool configuration (change) 2010-03-29

    Sql Code Weblogic access oracle database connection pool can be used three kinds of ways to configure JDBC One in the weblogic console in accordance with the following configuration to establish connection pool, and modify the file startWeblogic.cmd

  • Database connection pool 2010-02-06

    Database Connection Pool overview: Database connection is an expensive key limited resources, this web page in a multi-user applications, especially embodied. The management of the database connection can significantly affect the entire application s

  • Set the database connection pool (personal order) 2010-03-19

    To improve performance, if direct access to the database connection, performance is relatively low. Generally use a connection pool, connection pool to manage the database through the connection, so you can achieve an efficient operation of the role

  • About the database connection pool 2010-03-07

    Database connection is an expensive key limited resources, this web page in a multi-user applications, especially embodied. The management of the database connection can significantly affect the entire application scalability and robustness to the ap