JDBC driver download and connection string URL of various databases: java.sun.comproductsjdbcreferenceindustrysupportindex.html database description MySQLwww. mysql. comproductsconnectorjShipped. Butneedtodownload
JDBC driver download and connection string URL writing sun official website on the JDBC driver list: http://java.sun.com/products/jdbc/reference/industrysupport/index.html data library said MySQL http://www.mysql.com/products/connector/j/ Shipped. But need to download
JDBC driver download and connection string URL writing for various databases
JDBC driver list on sun Official Website:Http://java.sun.com/products/jdbc/reference/industrysupport/index.html
Data Base |
Description |
MySQL |
Http://www.mysql.com/products/connector/j/Shipped. But need to download the latest for MySQL 4.1 or higher. |
Oracle |
Http://www.oracle.com/technology/software/tech/java/sqlj_jdbc/index.htmlIncluded. |
SQL Server by jTDS |
Http://sourceforge.net/project/showfiles.php? Group_id = 33291Included. Support Microsoft SQL Server (6.5, 7, 2000 and 2005) |
Postgres |
Http://jdbc.postgresql.org/download.htmlIncluded 7.3 JDBC 3 |
SAP DB |
Http://www.sapdb.org/sap_db_jdbc.htmIncluded. |
SyBase by jTDS |
Http://jtds.sourceforge.net/Included. Support Sybase (10, 11, 12) |
The following content is from the Internet
1. MySQL (http://www.mysql.com) mysql-connector-java-2.0.14-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 );
9. Because access does not run as a service, the url method is not applicable to access. Access can be found in the form of odbc or server ing paths, see http://rmijdbc.objectweb.org/Access/access.html
How to Use JDBC APIs
(1) Register and load the JDBC driver;
Two methods:
Class. forName (String drivername );
DriverManager. registerDriver (Driver driver)
(2) establish a connection with the SQL database;
The getConnection () method of DriverManager:
Connection getConnection (String url): url indicates the database address String;
Connection getConnection (String url, String user, String pwd)
Connection getConnection (String url, Properties info)
(3) Send an SQL query;
The createStatement () method of Connection:
Statement createStatement ();
Statement can execute SQL statements to obtain SQL query results.
(4) obtain the result set.
Statement:
ResultSet executeQuery (String SQL): Execute the select statement.
Int executeUpdate (String SQL): Execute update statements, such as insert, delete, and update.
(5) search the query results.
ResultSet method:
Boolean next (): returns false if no rows exist;
String getString (String columnName): returns the value of the column name.