Home PC Games Linux Windows Database Network Programming Server Mobile  
           
  Home \ Programming \ Java uses JDBC connect database     - Java and Python use make way dictionary word search script (Programming)

- Linux suffered SYN flood attack setting (Linux)

- Use HugePages optimize memory performance (Database)

- Linux virtual machine settings network, hostname ssh access (Linux)

- Linux server network penetration testing (Linux)

- The Sublime Text 3 configuration file (Linux)

- File encryption and decryption of Linux security mechanisms (Linux)

- PF_RING 6.0.2 compiled and installed on Redhat 6.3 x86_64 (Linux)

- How to set up HTTPS policies for older browsers (Server)

- Install the Red Hat Container Development Kit on OSX (Server)

- Linux kernel RCU (Read Copy Update) lock Brief (Linux)

- Installation and Configuration rsync server under CentOS 6.3 (Server)

- How do I cancel (almost) any operations in Git, (Linux)

- HDFS Distributed File System Resource Manager Developer summary (Server)

- Lua study notes under ubuntu (Linux)

- How to use Evernote in the Linux command line (Linux)

- Availability Hadoop platform - Oozie Workflow (Server)

- ARM Linux system call (Linux)

- Zabbix Agent (Server)

- The AWK use Cygwin tools mysql binlog log viewer (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.

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:      
 
- Linux use additional rights (Linux)
- ORA-30926 and MERGE tables empty the temporary occupation problem (Database)
- Grep, Ack, Ag searches Efficiency Comparison (Linux)
- VMware11 virtual machine Ubuntu14.10 system partition sda1 disk expansion (Linux)
- Linux / UNIX: Use the dd command to create a 1GB size binary (Linux)
- C ++ Replication Control: Assignment operators and destructors (Programming)
- Java NIO in the world (Programming)
- Bash command substitution (Programming)
- Linux SSH commands (Linux)
- RHEL 6.6 install GNOME desktop environment (Linux)
- Graphics of Java Tools (Programming)
- Getting case of Python Hello World (Programming)
- Nonstandard IMP-00010 error processing one case (Database)
- Modify Linux terminal prompt path length (Linux)
- How to Install Cantata MPD 1.3.3 for Ubuntu and Derived Version Users (Linux)
- grep, egrep and regular expressions (Linux)
- MySQL enabled SSD storage (Database)
- Linux install the Java Runtime Environment and the output Hello World under (CentOS) (Linux)
- Simple security measures to reinforce the Linux kernel (Linux)
- Struts2 interceptor simulation (Programming)
     
           
     
  CopyRight 2002-2020 newfreesoft.com, All Rights Reserved.