JDBC02 load the JDBC driver to establish a connection

JDBC (Java Database Connection) provides a unified programming interface for Java developers to use the database

the sun's because they do not know each mainstream commercial database program code, it can not write your own code to connect to various databases, so the sun's own provides a set of API, those who want to connect with Java database, the database vendors themselves must implement this interface to JDBC , the JDBC data vendors to achieve, and we told him this database database-driven

Access the database process:

 

the try { 
            Class.forName ( "com.mysql.cj.jdbc.Driver" );
             Long Start = System.currentTimeMillis ();
             // establish a connection: a very time-consuming, the real development in the use of connection pool to manage connections 
            Connection conn = DriverManager. getConnection ( "? jdbc: MySQL: // localhost: 3306 / testjdbc & useSSL = false & serverTimezone = UTC" 
                    , "root", "******" ); 
            System.out.println (conn); 
            Long End = System. with currentTimeMillis (); 
            System.out.println ( "time-consuming to establish a connection:" + (Start-End) + "MS" );
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch(SQLException E) { 
            e.printStackTrace (); 
        } 
/ **
* the Output: establishing a connection Processed: 221mS
** /

 

Which required when establishing a connection URL (mysql8.0) = "jdbc: mysql: // localhost:? 3306 / testjdbc & useSSL = false & serverTimezone = UTC" (testjdbc for the database name)

username="root",password="******"

Because the database connection is essentially a Socket connection, time-consuming, the real development in the connection pool used to manage the connection object

 

Guess you like

Origin www.cnblogs.com/code-fun/p/11407632.html