Home IT Linux Windows Database Network Programming Server Mobile  
           
  Home \ Programming \ Java uses JDBC connect database     - Delegate in C # (Programming)

- Linux based serial programming (Programming)

- Varnish achieve page jump (Server)

- Ubuntu 14.04 Nvidia proprietary drivers for install two graphic cards (Linux)

- Install the system cleaning software under Linux: BleachBit 1.4 (Linux)

- Ubuntu 14.04 solved using MyEclipse 10.7 flash back (Linux)

- XenServer Virtual Machine Installation --- first ISO image file storage expansion (Linux)

- OpenSSH version smooth upgrade method (Linux)

- Why everybody ought to know LLVM (Linux)

- Xmanager Remote Desktop login CentOS 6.5 (Linux)

- How to find an IP address through the command line (Linux)

- Taught you how to build your own VPS server (Server)

- QEMU image file used: qcow2 and raw (Linux)

- Lua4.0 interpreter entrance (Programming)

- MySQL combination Git achieve differential backups can be used in the production environment (Database)

- Oracle 11g new features of the collection of multi-column statistics (Database)

- CRF ++ Linux use (Linux)

- CentOS 6.0 system security level (Linux)

- Redhat 5 prohibit IPv6 (Linux)

- Chkconfig command Detailed service is added and shut down the system in two ways to start service under Linux (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:      
 
- Shell Programming Regular Expressions (Programming)
- Oracle background processes daemons (Database)
- Android Application Development: an argument between Activity (Programming)
- Use small network command to check whether PC Security (Linux)
- Security: set limits on password (Linux)
- Spark local development environment to build (Server)
- Use FFmpeg processing high quality GIF (Programming)
- Source Analysis: Java object memory allocation (Programming)
- CentOS7 installed VMware 10 (Linux)
- CoreOS use register mirror to build private warehouse (Linux)
- Use ldap implement Windows Remote Desktop Ubuntu Linux (Linux)
- Java environment to build a number of issues (Linux)
- MySQL display operation control tips (Database)
- How Oracle implements random reads from specific combinations (Database)
- Atlassian Linux Shell Scripting the confluence remote backup methods (Linux)
- The multiplexed signal driving IO (Programming)
- installation of Vim plugin YouCompleteMe under Ubuntu 15.04 (Linux)
- Oracle table compression Technology Introduction (Database)
- Fun music library in Linux using command line (Linux)
- Use JMS listener Oracle AQ, trigger the execution of Java programs in the database changes (Database)
     
           
     
  CopyRight 2002-2016 newfreesoft.com, All Rights Reserved.