Jdbc:oracle:thin: @localhost: 1521:orcl Detailed

Source: Internet
Author: User

(Related data integration)

First, overall, this is a connection string to the Oracle database, indicating the URL of the connection database, which can be understood as three-part-〉 Protocol (JDBC): Sub-Protocol (Oracle:thin): Data source identification (@localhost: 1521:ORCL)

Second, Jdbc:java database Connectivity, which is a Java connection, is essentially a Java API that provides unified access to a variety of relational databases, consisting of a set of classes and interfaces written in the Java language. JDBC can do 3 things: 1, connect to database 2, send SQL statement 3, (from the database) receive processing results. From the connection string perspective, it indicates how JDBC is used to connect to the database.

Second, Oracle:thin

It is pointed out that the connection is the Oracle database, and the connection mode is thin mode, that is, the thin way, the client is not required. Another way to connect to it is fat: the CLI, which requires the client to be installed.

Third, @localhost: 1521:ORCL

The address of the localhost database, which can be pressed as the IP address of the database when not local;

1521 orcal database default listening port, can be swapped for other listening port;

ORCL a default instance of the Orcal database, which can be pressed as a different instance name.

Four, expand

Connection string for Java connection to other databases

-----mysql-----

driverstring = Com.mysql.jdbc.Driver

Databaseurl = Jdbc:mysql://127.0.0.1:3306/scutcs

-----ms SQL 2000-----

driverstring = Com.microsoft.jdbc.sqlserver.SQLServerDriver

Databaseurl = Jdbc:microsoft:sqlserver://localhost:1433;databasename=demo

-----ms SQL 2005-----

driverstring = Com.microsoft.sqlserver.jdbc.SQLServerDriver

Databaseurl = Jdbc:sqlserver://localhost:1433;databasename=demo

-----ms SQL third-party unified approach---

driverstring= Net.sourceforge.jtds.jdbc.Driver
Databaseurl = Jdbc:jtds:sqlserver://localhost:1433;databasename=demo

This method requires a third-party package: Jtds-1.2.jar;

-----db2-----

driverstring = Com.ibm.db2.jcc.DB2Driver
Databaseurl = Jdbc:db2://localhost:50000/toolsdb

V. Seven steps to connect to a database

1. Load Driver

Class.forName (driverstring);

2. Establish the connection

Connection conn = drivermanager.getconnection (databaseurl, username, password);

3. Create a statement

A. Execute static SQL statements, generally through Statement instance implementation, Eg:statement stmt = Conn.createstatement ();

B. Execute dynamic SQL statements, typically implemented by PreparedStatement instances, eg:preparedstatement pstmt = conn.preparestatement (sql);

C. Execution of stored procedures, typically implemented through CallableStatement instances, eg:callablestatement cstmt = Conn.preparecall ("{Call Demosp (?,?)}");

4. Execute SQL

The statement interface provides three ways to execute SQL statements: ExecuteQuery, executeupdate, and execute

A. ResultSet executeQuery (String sqlString): Executes the SQL statement that queries the database and returns a result set (ResultSet) object.

The specific statement is: ResultSet rs = stmt.executequery ("SELECT * from ...");

  b. int executeupdate (String sqlString): Used to execute INSERT, UPDATE, or DELETE statements, as well as SQL DDL statements such as CREATE table and drop table, etc.

The specific statement is: int rows = Stmt.executeupdate ("INSERT into ...");

C. Execute (String SQL): Used to perform statements that return multiple result sets, multiple update counts, or a combination of both.

Implementation-specific code: Boolean flag = Stmt.execute (sqlString)

5. Processing results

Result one: The execution query returns a ResultSet object (recordset)

Result two: The execution of the update returns the number of records affected by this operation.

Ways to access results:

   while (Rs.next ()) {

String name = rs.getstring ("name");

String PWDs = rs.getstring (1); This method is efficient

}

6. Close Resources

Reverse order closed, first inside out. Recordset-declaration-Connection

if (rs! = null) {

try{

Rs.close ();

}catch (SQLException e) {

E.printstacktrace (); E.printstacktrace ();

}

} ...

Jdbc:oracle:thin: @localhost: 1521:orcl Detailed

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.