1. Load the JDBC driver:
Before connecting to the database, first load the driver of the database you want to connect to the JVM (Java Virtual machine),
This is achieved through the static method forname (String className) of the Java.lang.Class class.
For example:
try{
Load the MySQL driver class
Class.forName ("Com.mysql.jdbc.Driver");
}catch (ClassNotFoundException e) {
System.out.println ("Driver class not found, load driver fai
is a pure Java driver and does not require additional configuration.
2, dynamic designation Classpath
If you need to dynamically specify CLASSPATH when executing, use the-CP method at execution time. Otherwise, add the. jar file above to the CLASSPATH environment variable.
3. Load 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
Technique | data | database Java database connection (JDBC) consists of a set of classes and interfaces written in the Java programming language. JDBC provides tools/database developers with a standard API that enables them to write database applications with a pure Java API. However, each developer's interface is not exactly the same, so the development environm
are using the Eclipse development tool, configure "Java build Path" and specific actions "click on Eclipse's Project->properties->java builds path-> Libraries "Now click on the right side of the Add External JARs and select the Mysql-connector-java-5.1.2.0-bin.jar driver click to open to complete the configuration."
The following is the example code that Java uses to connect MySQL data with jdbc:
Copy Code code as follows:
Import java.s
Java uses JDBC to connect to any type of Database (mysql oracle ..), Oraclejdbc
Package cn. liz. test; import java. io. inputStream; import java. SQL. connection; import java. SQL. driver; import java. SQL. SQLException; import java. util. properties; import org. junit. test; public class JBDCtest {/*** compile a common method to obtain the
specified database)", such as the code for a data driver loaded into MySQL: class.forname (" Com.mysql.jdbc.Driver ")3 . Create a data Connection object: Create a database Connection object Connectionthrough the DriverManager class. The DriverManager class acts between the Java program and the JDBC driver to check whether the loaded driver can establish a
=drivermanager.getconnection ("Jdbc:mysql://mydbserver?user=qingfengpassword=mingyue");......Conn.close ();catch (Exception e) ... {E.printstacktrace ();Finally ... {if (conn!=null) ... {Try ... {Conn.close ();catch (SQLException e) ... {}}}This is the traditional practice, but also the previous non-Java programmers (such as Delphi, VB, etc.) common practice. This is generally not a problem in a small-scale development process, as long as programmers are familiar with the Java language, understa
drivers, which the JDBC driver can use to create a bridge between Java programs and data sources. The application needs to be written once and can be moved to a variety of drivers. Sun provides a driver manager, database vendors-such as MySQL, Oracle, the driver provided to meet the requirements of the driver can be recognized, you can work properly. Therefore, JDBC
Getmajorversion: Gets the driver's major version number
Getminorversion: Gets the driver's version number
GetPropertyInfo (Url,prop): The parameter URL represents the address required to establish the connection, in the format jdbc:subprotocol:subname.
The JDBC representation is a fixed string th
The name of the class that implements Java.sql.Driver in MySQL connector/j is ' com.mysql.jdbc.Driver '. The ' Org.gjt.mm.mysql.Driver ' class name is also usable to remain backwards-compatible with MM. Mysql. You are should use this class name when registering the driver, or when otherwise configuring software to use MySQL connector/ J.
The JDBC URL format for MySQL connector/j are as follows, with items
be loaded by "class.forname (" The driver for the specified database)", such as the code for a data driver loaded into MySQL: class.forname (" Com.mysql.jdbc.Driver ")3 . Create a data Connection object: Create a database Connection object Connectionthrough the DriverManager class. The DriverManager class acts between the Java program and the JDBC driver to chec
Tags: div href journal oid pst STC Integer input RDS This blog provides a simple JDBC connection routine through the JDBC driver, and realizes the query to the database through statement and PreparedStatement respectively.The next blog will focus on the difference between statement and PreparedStatement.1. Join the JDBC
Jsp jdbc-based database connection instance and jspjdbc database connection
This example describes the JDBC-based database connection class of JSP. We will share this with you for your reference. The details are as follows:
/*** TODO To change the template for this generated
connection object, if the exception is not thrown to show that the connection is successful, we start with three parameters. The first parameter is a URL, his format is:jdbc: 对于 Oracle 数据库连接,采用如下形式:
jdbc:oracle:thin:@localhost:1521:sid
对于 SQLServer 数据库连接,采用如下形式:
jdbc:microsoft:sqlserver//localhost:1433; DatabaseName=
JDBC Connection database OverviewCommon Methods for connecting to a database through JDBC are summarized as follows:1. JDBC connection to DB2Class. forname ("com.ibm.db2.jdbc.net. db2driver ");String url = "
The Connection object represents a connection to the database. The connection process includes the executed SQL statement and the results returned on that connection. An application can have one or more connections to a single database, or it can be connected to many databases. 2.1.1 The standard way to open a
Programs that generally get database connectionsClass.forName ("Com.mysql.jdbc.Driver"), final Connection Connection = (Connection) drivermanager.getconnection ("jdbc : Mysql://localhost:3306/testdb "," guoxiaoming "," guoxiaoming ");-----------------------------Register MySQL driver class next time, we are now focusin
());
2 drivermanager.deregisterdriver (driver); Operation Get Properties
Getmajorversion: Gets the driver's major version number
Getminorversion: Gets the driver's version number
GetPropertyInfo (Url,prop): The parameter URL represents the address required to establish the connection, in the format jdbc:subprotocol:subname.
The
connection peripheral application configurator -----> MSSQLServer ----> remote connection ----> select local connection and remote connection to use TCP/IPMySQLClass. forname ("org. gjt. Mm. MySQL. Driver"); // This is a string of the old version. Currently, it is com. MySQL. JDBC
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.