The examples in this article describe how Java connects to various databases. Share to everyone for your reference. Specifically as follows:
Copy Code code as follows:
Mysql:
String driver= "Com.mysql.jdbc.Driver"; Driver Program
String url= "Jdbc:mysql://localhost:3306/db_name"; The url,db_name of the connection is the database name
String username= "Username"; User name
String password= "Password"; Password
Class.forName (Driver). newinstance ();
Connection con=drivermanager.getconnection (Url,username,password);
Microsoft SQL Server 2.0 driver (one of 3 jars):
String driver= "Com.microsoft.jdbc.sqlserver.SQLServerDriver"; Ways to connect to SQL databases
String url= "Jdbc:microsoft:sqlserver://localhost:1433;databasename=db_name"; Db_name for Database name
String username= "Username"; User name
String password= "Password"; Password
Class.forName (Driver). newinstance (); Load data to drive
Connection con=drivermanager.getconnection (Url,username,password); //
Microsoft SQL Server 3.0 driver (one of 1 jars)://Old Zi Zhu Perfect
String driver= "Com.microsoft.sqlserver.jdbc.SQLServerDriver"; Ways to connect to SQL databases
String url= "Jdbc:microsoft:sqlserver://localhost:1433;databasename=db_name"; Db_name for Database name
String username= "Username"; User name
String password= "Password"; Password
Class.forName (Driver). newinstance (); Load data to drive
Connection con=drivermanager.getconnection (Url,username,password); //
Sysbase:
String driver= "Com.sybase.jdbc.SybDriver"; Driver Program
String url= "Jdbc:sysbase://localhost:5007/db_name"; Db_name is a data name
String username= "Username"; User name
String password= "Password"; Password
Class.forName (Driver). newinstance ();
Connection con=drivermanager.getconnection (Url,username,password);
Oracle (in thin mode):
String driver= "Oracle.jdbc.driver.OracleDriver"; Ways to connect to a database
String url= "Jdbc:oracle:thin: @loaclhost: 1521:ORCL"; ORCL is the SID of the database
String username= "Username"; User name
String password= "Password"; Password
Class.forName (Driver). newinstance (); Load Database Driver
Connection con=drivermanager.getconnection (Url,username,password);
PostgreSQL:
String driver= "Org.postgresql.Driver"; Ways to connect to a database
String url= "Jdbc:postgresql://localhost/db_name"; Db_name is a data name
String username= "Username"; User name
String password= "Password"; Password
Class.forName (Driver). newinstance ();
Connection con=drivermanager.getconnection (Url,username,password);
DB2:
String driver= "Com.ibm.db2.jdbc.app.DB2.Driver"; Connecting a provider instance with a DB2 client
String driver= "Com.ibm.db2.jdbc.net.DB2.Driver"; The connection does not have a provider instance of the DB2 client
String url= "Jdbc:db2://localhost:5000/db_name"; Db_name is a data name
String username= "Username"; User name
String password= "Password"; Password
Class.forName (Driver). newinstance ();
Connection con=drivermanager.getconnection (Url,username,password);
Informix:
String driver= "Com.informix.jdbc.IfxDriver";
String url= "Jdbc:informix-//sqli://localhost:1533/db_name:informixser=myserver"; Db_name is a data name
String username= "Username"; User name
String password= "Password"; Password
Class.forName (Driver). newinstance ();
Connection con=drivermanager.getconnection (Url,username,password);
JDBC-ODBC:
String driver= "Sun.jdbc.odbc.JdbcOdbcDriver";
String url= "Jdbc:odbc:dbsource"; Dbsource for data source name
String username= "Username"; User name
String password= "Password"; Password
Class.forName (Driver). newinstance ();
Connection con=drivermanager.getconnection (Url,username,password);
I hope this article will help you with your Java programming.