JDBC uses the database URL to describe the database driver. The database URL is similar to a generic URL, but sun simplifies the definition with the following syntax:
Jdbc: : [Node]/[database]
Where the Child Protocol (subprotocal) defines the driver type, node provides the location and port number of the network database, followed by an optional parameter. For example:
Represents the use of the Inetdae driver to connect to the MyServer database server on port 1433, select the language as U.S. English, and the version of the database is MSSQL Server 7.0.
The Java application loads a driver class by specifying DriverManager. The syntax is as follows:
Class.forName (" ”);
Or
Class.forName (" "). newinstance ();
Then, DriverManager creates a specific connection:
The connection interface connects the database by specifying the database location, login name, and password. Connection interface creates a statement real
Example executes the query you want:
Statement stmt=connection.createstatement ();
Statement has a variety of methods (APIs), such as Executequery,execute, that can return a query's result set. The result set is a ResultSet object. Specific can be developed through the JDBC document view. can be downloaded at Sun's site
The following example illustrates:
Import java.sql.*; Enter JDBC Package
String url = "jdbc:inetdae:myserver:1433";//host name and port
String login = "user";//Login name
String password = "";//Password
try {
Drivermanager.setlogstream (System.out); file://open a stream for displaying some information
FILE://calls the driver, whose name is Com.inet.tds.TdsDriver
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.