Home PC Games Linux Windows Database Network Programming Server Mobile  
  Home \ Programming \ Java uses JDBC connect database     - Oracle 11g modify MEMORY_TARGET (Database)

- Java interface and inheritance (Programming)

- Read and write files efficiently from Apache Kafka (Server)

- CentOS 6.5_x64 install Oracle 11g R2 (Database)

- Several back door and log tool under Linux (Linux)

- Linux regex awk Comments (Linux)

- Vim useful plugin: YouCompleteMe (Linux)

- C ++ constant definition (Programming)

- Ubuntu install Lighttpd + Mono support .net (Linux)

- Hibernate Search 5.5 in the search results sorted (Linux)

- Linux data recovery software efficiently practical application extundelete (Linux)

- The difference between vi and nano (Linux)

- Construction of Android and iOS apps use Jenkins Automation (Programming)

- Linux System Getting Started Tutorial: Installing Brother printer in Linux (Linux)

- Examples of safety testing system notes for RedHat Linux (Linux)

- Incremental garbage collection mechanism for Ruby 2.2 (Programming)

- Unetbootin make use U disk loading Linux system (Linux)

- How to install Linux Kernel 4.4 on Ubuntu (Linux)

- After installing minimize RHEL / CentOS 7 need to do some things (Linux)

- MySQL full-index scan bug (Database)

  Java uses JDBC connect database
  Add Date : 2018-11-21      
  Develop a JDBC application, the basic needs of the following steps:

1. The JDBC driver class is loaded into the JAVA virtual machine. Use the static method forName java.lang.Class class (String className) implementation.

Example: Class.forName ( "JDBC driver class name")

2. load the driver, and establishes a connection to the database. DriverManager class followed by a registered driver, when we call the getConnection () method, which will traverse the list of drivers until a match on the connection string to connect to the data specified in the driver database, after loading the driver, use getConnection method of the DriverManager class to establish a connection between the database.


Connection con = DriverManager.getConnection (database connection string, database user name, password)
3. Send the SQL statement and get the result set. Create a Statement interface instance and SQL statements to the database it is connected.

 Statement instance is divided into three types:

 (1) executing a static SQL statements. Usually achieved by Statement instance.

 (2) execute dynamic SQL statements. Typically implemented by PreparedStatement instance.

 (3) the implementation of database stored procedures. Usually through CallableStatement instance.


Statement stmt = con.createStatement ();
ResultSet rs = stmt.executeQuery ( "select * from table1");
 Statement interface provides three methods execute SQL statements: executeQuery, executeUpdate, execute statement.

ResultSet executeQuery (String sqlString): execute SQL statements to query the database and returns a result set (ResultSet) object.
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.
execute (sqlString): used to perform return multiple result sets, count, or a combination of both multiple update statements.

ResultSet rs = stmt.executeQuery ( "SELECT * FROM ...");
int rows = stmt.executeUpdate ( "INSERT INTO ...");
boolean flag = stmt.execute (String sql);

4. results. Results are divided into two situations:

(1) to perform the update returns this number of records affected by the operation.

 Results (2) to execute the query returns a ResultSet object.


while (rs.next ()) {
         int x = rs.getInt ( "a");
         String s = rs.getString ( "b");
         float f = rs.getFloat ( "c");
5. Close the JDBC objects

  After the operation is complete, close all JDBC objects to be used to release JDBC resources, closed in reverse order and declaration order.

 (1) off the record set

 (2) Close Statement

 (3) close the connection object

 if (rs! = null) {// set off the record
        try {
            rs.close ();
        } Catch (SQLException e) {
            e.printStackTrace ();
          if (stmt! = null) {// Close Statement
        try {
            stmt.close ();
        } Catch (SQLException e) {
            e.printStackTrace ();
          if (conn! = null) {// Close the connection object
         try {
            conn.close ();
         } Catch (SQLException e) {
            e.printStackTrace ();
- Ubuntu font settings: Using Windows Font (Linux)
- Zypper command for SUSE Linux package management (Linux)
- To modify the existing user ID and comments GPG key (Linux)
- Python MySQL database connection (Database)
- Create and modify Oracle temporary table space (Database)
- Taught you how to install Ubuntu Linux (Linux)
- Linux install deploy Ansible (Linux)
- Linux character device - user mode and kernel mode data transfer data (Linux)
- Introduction and MongoDB CRUD (Database)
- C ++ input and output summary _ Input (Programming)
- Linux System Getting Started Learning: Fix ImportError: No module named scapy.all (Linux)
- Manage SQL Server services login (start) account and password (Database)
- Https (SSL / TLS) Detailed principles (Server)
- Teach you how to protect the Linux operating system security tips (Linux)
- Linux NIC driver and version information (Linux)
- Initialization and starting process of Linux (Linux)
- To install Docker under CentOS7 (Linux)
- Ubuntu users to install Gnome-Pie 0.6.5 (Linux)
- Android to determine whether the device to open WIFI, GPRS data connection (Programming)
- Linux Basic Course: tar command description (Linux)
  CopyRight 2002-2020 newfreesoft.com, All Rights Reserved.