Home PC Games Linux Windows Database Network Programming Server Mobile  
           
  Home \ Programming \ Java uses JDBC connect database     - Ubuntu comes with gedit editor to add Markdown preview widget (Linux)

- Linux Change ssh port and disable remote root login at (Linux)

- OpenSSH version smooth upgrade method (Linux)

- Linux Learning --- disk partition / relational representation + mount (Linux)

- Install Oracle 11g illustrations and dependent libraries under SUSE11 (Database)

- A key installation Gitlab 7 on RHEL6.4 and Setup Mail TX (Linux)

- CentOS of NFS (Server)

- NFS installation process under the CentOS (Linux)

- Linux prohibit non-WHEEL user su command Detail (Linux)

- Using Oracle for Oracle GoldenGate to achieve a one-way data synchronization (Database)

- Restore database fault encountered ORA-0600 (Database)

- shell script: a key to install LAMP, LNMP script (Server)

- JBPM6 Tutorial - taught you how to install JBPM (Linux)

- Bash mathematical extension (Programming)

- Shell Programming points to note about the function (Programming)

- Bad name two variables (Linux)

- Python substring format (Programming)

- Enterprise-class GitHub warehousing environment build (Server)

- Exploring the Android Listview display confusion (Programming)

- GitLab issued Merge Request return error 500 when the two solutions log (Linux)

 
         
  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.

example:

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.

example:

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.
  example:

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.

example:

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 ();
         }
          }
     
         
         
         
  More:      
 
- Correlation Analysis: FP-Growth algorithm (Programming)
- Setting Squid successful anti-hotlinking (Linux)
- Three easy open source firewall on the Linux platform (Linux)
- Iptables principle (Linux)
- Based on OpenSSL for HTTPS service configuration (Server)
- Oracle 11g tracking and monitoring system-level triggers to drop misuse (Database)
- Command line tool Tmux (Linux)
- Use Markdown editor for document work under Linux (Linux)
- Linux maximum number of threads and limit the number of queries the current thread (Linux)
- How to download GOG games in Linux command line (Linux)
- How to turn Java String into Date (Programming)
- What is a logical partition management LVM, how to use in Ubuntu (Linux)
- Android imageView in the Src and Background (Programming)
- Linux + Apache + PHP + Oracle based environment to build (Server)
- Linux server dual-card dual-IP and single-card dual-IP configuration method (ReHat / CentOS) (Server)
- Ubuntu 14.04 / 13.10 users how to install Ubuntu Touch core applications (Linux)
- LNMP Note: Addressing mail function can not send mail (Server)
- Java Timer (regular calling, to achieve a fixed time to perform) (Programming)
- sed command (Linux)
- Through eight skills to let you become a super Linux end-user (Linux)
     
           
     
  CopyRight 2002-2022 newfreesoft.com, All Rights Reserved.