List of database connection

2010-09-28  来源:本站原创  分类:Database  人气:153 

Java Database Connectivity (JDBC) by a group of Java programming language using classes and interfaces. JDBC as a tool / database developers provides a standard API, so that they can use pure Java API to write database applications. However, the interface is not identical to each developer, so development will bring some changes in the environment configuration changes. In this paper, a different set of database connections.
First, connect a variety of database lookup tables below list a variety of ways using the JDBC database connection, it can be used as a guide.
1, Oracle8/8i/9i database (thin model)
Class.forName ("oracle.jdbc.driver.OracleDriver"). NewInstance ();
String url = "jdbc: oracle: thin: @ localhost: 1521: orcl"; / / orcl SID for the database
String user = "test";
String password = "test";
Connection conn = DriverManager.getConnection (url, user, password);
2, 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);
3, Sql Server7.0/2000 database
Class.forName ("com.microsoft.jdbc.sqlserver.SQLServerDriver"). NewInstance ();
String url = "jdbc: microsoft: sqlserver: / / localhost: 1433; DatabaseName = mydb";
/ / Mydb database
String user = "sa";
String password = "";
Connection conn = DriverManager.getConnection (url, user, password);
4, Sybase Database
Class.forName ("com.sybase.jdbc.SybDriver"). NewInstance ();
String url = "jdbc: sybase: Tds: localhost: 5007/myDB"; / / myDB name for your database
Properties sysProps = System.getProperties ();
SysProps.put ("user", "userid");
SysProps.put ("password", "user_password");
Connection conn = DriverManager.getConnection (url, SysProps);
5, Informix Database
Class.forName ("com.informix.jdbc.IfxDriver"). NewInstance ();
String url = "jdbc: informix-sqli: / / 123.45.67.89:1533 / myDB: INFORMIXSERVER = myserver;
user = testuser; password = testpassword "; / / myDB name for the database
Connection conn = DriverManager.getConnection (url);
6, MySQL database
Class.forName ("org.gjt.mm.mysql.Driver"). NewInstance ();
String url = "jdbc: mysql: / / localhost / myDB? User = soft & password = soft1234 & useUnicode = true & characterEncoding = 8859_1"
/ / MyDB name for the database
Connection conn = DriverManager.getConnection (url);
7, PostgreSQL Database
Class.forName ("org.postgresql.Driver"). NewInstance ();
String url = "jdbc: postgresql: / / localhost / myDB" / / myDB name for the database
String user = "myuser";
String password = "mypassword";
Connection conn = DriverManager.getConnection (url, user, password);
8, access database, ODBC-Direct Used
Class.forName ("sun.jdbc.odbc.JdbcOdbcDriver");
String url = "jdbc: odbc: Driver = (MicroSoft Access Driver (*. mdb)); DBQ =" + application.getRealPath ("/ Data / ReportDemo.mdb");
Connection conn = DriverManager.getConnection (url ,"","");
Statement stmtNew = conn.createStatement ();
Second, JDBC connection MySql JDBC connection method is to use MySql following a small tutorial 1, to find the driver currently available java MySQL driver for Connection / J, can be downloaded from the MySQL website, and find the mysql-connector-java-3.0 .15-ga-bin. jar file, the driver for the pure java driver, no need to do other configurations.
2, the dynamic specified classpath
If you need to perform dynamically specified classpath, in execution mode with-cp. Otherwise the above. Jar files into the classpath environment variable.
3, load the driver
try (
Class.forName (com.mysql.jdbc.Driver);
System.out.println (Success loading Mysql Driver!);
) Catch (Exception e)
(
System.out.println (Error loading Mysql Driver!);
e.printStackTrace ();
)
4, set the connection url
jdbc: mysql: / / localhost / databasename [? pa = va] [& pa = va]

Careful who may have seen the problem, how to mySql link to download the rar files of different, to extract the files inside the jar out and copy it into your web application's WEB-INF \ lib under the (of course, you can set the CLASSPATH )
Then modify the program code:
Your:
Class.forName ("org.gjt.mm.mysql.Driver"). NewInstance ();
Read:
Class.forName ("com.mysql.jdbc.Driver");
Added:
1, not from the application of the same name
E: \ Tomcat 5.0 \ webapps \ ROOT \ WEB-INF \ lib
The above is the Tomcat ROOT application of their own, your own application to another from a different name, such as my-test
2, reported the following error:
java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
Can not find the driver class is to represent not it?
Said the driver jar file is not properly placed, you downloaded a rar, just extract the files inside the jar out on the line, and copy it to your application directory \ WEB-INF \ lib, such as your Applications were called just said my-test, refer to the application directory level:
Tomcat 5.0
\ Webapps
\ My-test
\ WEB-INF
\ Lib
\ Mysql-connector-java-3.1.11-bin.jar

相关文章
  • 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

  • Hibernate support package DBCP database connection pool configuration 2009-04-09

    Hibernate support package DBCP database connection pool configuration. A brief description of the configuration process: (Just a personal feeling, if questions are welcome to show) Required packages: Commons-Pool (download Address: http://jakarta.apa

  • hibernate configuration data source. hibernate - Database Connection Pool 2009-04-30

    In order to configure their own testing environment, and required their entire framework of the abstract, the introduction of the test framework, the tests have their own test cases. Database connection pool but found the old problems, questions and

  • Hibernate database connection and SQL dialect collections (reprint) 2009-06-23

    Hibernate database connection and SQL dialects Favorites <session-factory> <property name="connection.driver_class"> net.sourceforge.jtds.jdbc.Driver </ property> <property name="connection.url"> jdbc: jtds: sql

  • 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

  • Hibernate configuration file hibernate.cfg.xml to configure the database connection 2010-03-29

    If you are using hibernate developed, then a clear understanding of the hibernate configuration would be helpful. The following summary is to find the information and, if wrong, please let us point out, thank you ~ The following is on the JDBC connec

  • 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

  • mql database connection 2010-03-29

    public final class HibernateUtil { private static SessionFactory sessionFactory = null; private static String path = Common.decode(Thread.currentThread().getContextClassLoader().getResource("../../config.properties").getPath()); private static S

  • 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 Pool 2009-10-24

    Although using APACHE COMMONS DBCP can be very convenient to establish a database connection pool, However, as this article within the database connection pool principles written in such a thorough look so complete, Is really very rare, so that devel

  • 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

  • An effect is very nice JAVA database connection pool 2009-08-05

    import java.sql.Connection; import java.sql.DatabaseMetaData; import java.sql.Driver; import java.sql.DriverManager; import java.sql.SQLException; import java.sql.Statement; import java.util.Enumeration; import java.util.Vector; /* Although the use o

  • DBCP database connection failure solution (Io exception: Connection reset) 2010-02-23

    Many commented that the DBCP web there are many BUG, but did not specify what is BUG, only a few people say that if for some reason cut off the database after the connection is via DBCP connection failure, but not to re-take. Some time will be report

  • oracle database connection pool 2009-08-21

    J2EE applications with Oracle database connection in the J2EE application development, application and database connection establishment is one of the problems we often encounter. Here I will mainly talk about in local applications through OCI way, t

  • [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

  • NET ORACLE database connection methods and the sample (turn) 2010-03-07

    . NET to connect to ORACLE database there are three kinds of methods: 1.OLEDB way, this approach requires you to install the oracle client, do the last two years on the oracle database, I have adopted this approach, although a bit slow connection, bu

  • 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