Basic JDBC learning and basic jdbc

Source: Internet
Author: User

Basic JDBC learning and basic jdbc

1. Concept: java Database Connection Technology

2. JDBC:Is a specification that provides Interfaces(Interface-Oriented Programming)

3. jdbc api:Provides interfaces and classes called by programmers, Integrated in the java. SQL and javax. SQL packages. For example:DriverManager class (managing different JDBC drivers), Connerction interface, Statement interface, and ResultSet Interface

4. jdbc api main functions:Establish connections with databases, execute SQL statements, and process results

5. Three interfaces:

 

<1> Connerction interface:Connects to the database and transmits data.

 

<2> Statement interface: this interface is generated by Connection and is responsible for executing SQL statements.

 

<3> ResultSet interface: maintains the query results generated after Statement execution.

6. JDBC steps:

 

1. Load the JDBC driver

 

Class. forName (JDBC Driver Class );

 

2. Establish a connection with the database

 

Connection conn = Drivermanager. getConnection (URL, database username, password );

 

3. Send SQL statements and get the returned results

 

Statement stmt = conn. creteStatement ();

 

ResultSet rs = stmt = executeQuery ("SELECT a FROM Table1 ");

 

Iv. handling results

 

While (rs. next ()){

 

Int x rs. getInt ("");

 

}

 

5. release resources

 

Rs. close ();

 

Stmt. close ();

 

Conn. close ();

 

Template

 

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.