I. understand JDBC
JDBC concept : adopt Java Code operation database ( increase , Delete , change , check ).
II.JDBC Operation steps :
1. Import jar package 2. Registration driver : Class.forName("com.mysql.jdbc.Driver") 3. Get driver : String url =
"jdbc:mysql://127.0.0.1:3306/ee"; //ee Is the name of the database Connection conn =
DriverManager.getConnection(url,"root", "123"); 4. Get operation object : Statement stat =
conn.createStatement();5. operation SQL: int num = stat.executeUpdate(sql); 6. Release resources : stat.
close(); conn.close();

III.JDBC Introduction to each class
1,DriverManager Drive Manager : A. Registration driver Original registration driven code Class.forName("com.mysql.jdbc.Driver"
); Driver The underlying code is DriverManager.registerDriver(new Driver()); B. Get connection String url
= "jdbc:mysql://127.0.0.1:3306/ee"; //ee Is the name of the database Connection conn = DriverManager.
getConnection(url,"root", "123");
=========================================================================== 2
,Connection Connect to database A. Get the object of the execution database a. Get the object of execution database directly Statement stat = conn.
createStatement(); b. Get preset statement execution database object PrepareStatement ps = conn.
prepareStatement(sql sentence ); B. Management affairs a. Open transaction conn.setAutoCommit(false);
//false Set to manually commit transactions .true Set to auto submit b. Commit transaction conn.commit(); c. Rollback transaction conn.rollback();
=========================================================================== 3
,Statement Operation database A. update operation (DML" Addition, deletion and modification of table records " and DDL" Addition, deletion and modification of tables and libraries ") int num = stat.
executeUpdate("SQL sentence "); // there SQL Sentence is adding, deleting and modifying . How many lines are affected B. Query operation (DQL" Querying table records ") ResultSet
resu= stat.executeQuery("SQL Query statement "); // there SQL Statement is a query statement DQL
=========================================================================== 4,
ResultSet Query table result set A. Determine if the next data still exists boolean b = resu.next(); // If the next data exists , The return value is true
Return if no false B. Get the data in the result set a. Result set found by query , Index value acquisition ( Index value from 1 start ) int data01 = resu.getInt(1);
// Get the query result set index as 1 Of int Data of type String data02 = resu.getString(2);
// Get the query result set index as 2 Of String Data of type b. Result set found by query , Column name get int data01 = resu.getInt("id");
// Get the query result set column name as id Of int Data of type String data02 = resu.getString("name");
// Get the query result set column name as name Of String Data of type
=========================================================================== 5
,PrepareStatement Operation database A. Get preset operation select * from user where username = ? and
password= ?; PreparedStatement ps = Connection.prepareStatement(sql);
// By presetting objects , Get connected operation B. Set parameters ps.setString(1,"root"); // parameter 1: Question mark , parameter 2: Corresponding preset value ps.
setString(2,"123");// parameter 1: Question mark , parameter 2: Corresponding preset value C. implement SQL sentence ps.executeQuery();

Technology
©2019-2020 Toolsou All rights reserved,
Python+OpenCV Detailed explanation of face recognition technology SpringBoot practice ( five ):mybatis-plus In BaseMapper,Iservice and ServiceImpl Google says home office affects work efficiency !2021 Return to offline office in 2010 C Language programming to find a student's grade vue Of v-if And v-show The difference between C Language console games , Make bricks These songs , Programmers, don't listen ! What should I do if I suddenly encounter a question I can't answer during the interview ?python To solve the problem of dictionary writing list in c Linguistic 5 Three common sorting methods