Home PC Games Linux Windows Database Network Programming Server Mobile  
  Home \ Programming \ Java uses JDBC connect database     - Common Linux system performance monitoring command (Linux)

- Logging information through the web GUI (LogAnalyzer) (Server)

- Android basics summary article (Programming)

- To install Cinnamon desktop environment on your Ubuntu 14.04 / 12.04 (Linux)

- Red Flag Linux Desktop 6.0 hard disk installation guide (Programming)

- MySQL stored procedures and triggers (Database)

- Deepin Tutorial: Depth Description Installer expert mode (Linux)

- GAMIT learning materials finishing (Linux)

- Linux user status query, and to unlock locked user (Linux)

- 256 with rich colors decorate your terminal (Linux)

- Ubuntu install video conversion tool Selene (Linux)

- Linux common network tools: batch scanning of hosting services netcat (Linux)

- Wine 1.7 is installed on a system based on RedHat or Debian (Linux)

- VMWare virtual machine without rebooting way to add virtual disk (Linux)

- Ubuntu Linux use ufw or iptables firewall configuration (Linux)

- Java memory model subclasses (Programming)

- ethtool implementation framework and application in Linux (Linux)

- Linux beginners to develop the seven habits (Linux)

- Hadoop new and old version of the difference in the size of the InputSplit (Server)

- Modifying the system registry protection server security (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.


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 ();
- Python common data type summary (Programming)
- Unity Greeter Badges: the lost session icon back to the login screen Ubuntu (Linux)
- SSH without password (Linux)
- JBPM6 Tutorial - Fast Fun JBPM table (Linux)
- Oracle 11g user rights management study notes (Database)
- Ubuntu Linux to create and increase the Swap partition tutorial (Linux)
- Linux add a new hard disk (Linux)
- Nginx caching using the official guide (Server)
- Two kinds of agents of Spring AOP (Programming)
- Scope of variables in C # (Programming)
- How to download apk file from the Google Play store on Linux (Linux)
- Mongo-connector integrated MongoD to achieve incremental Solr index (Server)
- Cobbler remotely install CentOS system (Linux)
- Understand the security restore accidentally deleted critical system files (Linux)
- How to use the ps command to monitor progress in the implementation of Linux commands (Linux)
- How to Set Free SSH password on CentOS / RHEL (Linux)
- Linux system security reinforcement (Linux)
- Ubuntu Learning Advanced article - to teach you to further enhance system security (Linux)
- Install VMware Tools in Debian (Linux)
- Zabbix monitoring of the switch (Server)
  CopyRight 2002-2022 newfreesoft.com, All Rights Reserved.