jdbc? ??????? ???? ??: 1. jdbc ???? ?? 2. ?????? ?? ?? 4. SQL ? ?? 6. ?? ?? ? ?? JDBC ?? ??.
? ??? ?? ??: windows10 ???, java 1.8, thinkpad t480 ???.
JDBC? ??????? ????? ?? ??? ???? JDBC? ??????? ???? ????? ????.
?? JDBC? ??? 4?? ????(???, ????, URL, ???????)? ?????.
(1) user user name
(2) Password
(3) URL? ??????? ??? ? ????, ?? ???? ? ??? ?? ???? ???? ???? ?????. ?? ??: ????: ??????: ??? ?? ??? ????: JDBC?? ?? jdbc? ?????. ??????: ??? ??? ???? ?? ?????? ?? ???? ?????.? ?
? ??? ?? ??: ?????? ??? ??? ??? ?? ??? ?????.? ? ?: (MySql ?? URL) ?
? jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=gbk ? ?
? useUnicode=true: ???? ?? ??? ???? ?????. CharacterEncoding? gb2312 ?? GBK? ??? ?? ? ????? true? ???? ???. CharacterEncoding=gbk: ?? ??? ??.
(4) ??????? ????? ???? ??? ????? ?????.
1. JDBC ???? ??:
??????? ???? ?? ?? JVM(Java Virtual Machine)? ????? ??????? ????? ???? ???. ?? forName(String className) ?? ???? ?? ?????. ) java.lang.Class ???? ?????.??
?: ??try{//加載MySql的驅(qū)動類 Class.forName("com.mysql.jdbc.Driver") ; }catch(ClassNotFoundException e){ System.out.println("找不到驅(qū)動程序類 ,加載驅(qū)動失??!"); e.printStackTrace() ; }
??? ???? Driver ???? ????? DriverManager ???? ?????.?
? ? ??????? ???? ???? ?????? ??? ???? java.sql.DriverManager??? Connection ??? ???? ??? ???.? ?
//連接MySql數(shù)據(jù)庫,用戶名和密碼都是root String url = "jdbc:mysql://localhost:3306/test" ; String username = "root" ; String password = "root" ; try{ Connection con = DriverManager.getConnection(url , username , password ) ; }catch(SQLException se){ System.out.println("數(shù)據(jù)庫連接失?。?quot;); se.printStackTrace() ; }3. prepareStatement ??
?SQL ?? ????? java.sql.Statement ????? ??? ???.
? 2. ?? SQL?? ????. ????? ReadyStatement ????? ?? ?????.?
? 3. ?????? ?? ????? ?????. ????? CallableStatement ????? ?? ?????.現(xiàn) ? ???? ?? ??:statement stmt = con.createStatement ();
PreparedStatement PSTMT = con.preparestatement (SQL); L decosp (?,?)} ");
4. SQL ? ??
?The Statement ?????? SQL ?? ???? ? ?? ??? ExecuteQuery, ExecuteUpdate ? Execution? ?????.
1. ResultSet ExecuteQuery(String sqlString): ??????? ???? SQL ?? ???? ?? ??(ResultSet) ??? ?????.
2. int excuteUpdate(String sqlString): CREATE TABLE ? DROP TABLE ?? ?? INSERT, UPDATE ?? DELETE ?? SQL DDL ?? ???? ? ?????.
??? ?? ??: ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?? ’ s ’ ?? ?? ’s ’ ?? ’s ‐ to ‐ n n ‐ ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? mt.execute( String sql) ;
5. ?? ?? ?? 兩種情況:
1、執(zhí)行更新返回的是本次操作影響到的記錄數(shù)。
2、執(zhí)行查詢返回的結(jié)果是一個ResultSet對象。
? ResultSet包含符合SQL語句中條件的所有行,并且它通過一套get方法提供了對這些
行中數(shù)據(jù)的訪問。
? 使用結(jié)果集(ResultSet)對象的訪問方法獲取數(shù)據(jù):
while(rs.next()){
String name = rs.getString("name") ;
String pass = rs.getString(1) ; // 此方法比較高效
}
(列是從左到右編號的,并且從列1開始)
6、處理異常,關(guān)閉JDBC對象資源
?操作完成以后要把所有使用的JDBC對象全都關(guān)閉,以釋放JDBC資源,關(guān)閉順序和聲 明順序相反:
1、先關(guān)閉requestSet
2、再關(guān)閉preparedStatement
3、最后關(guān)閉連接對象connection
if(rs !=null){ // 關(guān)閉記錄集 try { rs.close(); } catch (SQLException e) { e.printStackTrace(); } } if(stmt !=null){ // 關(guān)閉聲明 try { stmt.close(); } catch (SQLException e) { e.printStackTrace(); } } if(conn !=null){ // 關(guān)閉連接對象 try { conn.close(); } catch (SQLException e) { e.printStackTrace(); } }
相關(guān)視頻教程:java視頻教程
? ??? jdbc? ???? ??????? ???? ??? ??????? ?? ?????. ??? ??? PHP ??? ????? ?? ?? ??? ?????!

? AI ??

Undress AI Tool
??? ???? ??

Undresser.AI Undress
???? ?? ??? ??? ?? AI ?? ?

AI Clothes Remover
???? ?? ???? ??? AI ?????.

Clothoff.io
AI ? ???

Video Face Swap
??? ??? AI ?? ?? ??? ???? ?? ???? ??? ?? ????!

?? ??

??? ??

???++7.3.1
???? ?? ?? ?? ???

SublimeText3 ??? ??
??? ??, ???? ?? ????.

???? 13.0.1 ???
??? PHP ?? ?? ??

???? CS6
??? ? ?? ??

SublimeText3 Mac ??
? ??? ?? ?? ?????(SublimeText3)

Apple? ?? iOS18, iPadOS18 ? macOS Sequoia ??? ????? ?? ??????? ??? ??? ???????. ? ??? ???? ??? ??? ????? ??? ??? ???? ?? ??? ? ??? ???????. ??? ???? ?? ?? ?? ??? '???'??? ??? ???????. ? ??? ???? ??? ?? ?????? ???? ?? ???? ???? ??? ?? ? ???? ?????. "???" ??? ??? ?????? ???? ?? ??? ??? ???, ?? ?????? ???? ???? ?? ??? ?? ???? ?? ?? ?????? ???? ?? ?? ????? ?? ???? ?????. ???? ? ?? ??? ??? ??? ???.

JSON ???? gjson ????? ?? json.Unmarshal ??? ???? MySQL ??????? ??? ? ????. gjson ?????? JSON ??? ?? ???? ??? ??? ????, json.Unmarshal ???? JSON ???? ?????? ?? ?? ?? ???? ?????. ? ?? ?? SQL ?? ???? ?? ??? ???? ???? ??????? ???? ???.

MySQL? ?? ?? ??? ?????? ?? ??????. 1) ?????? ? ??? ?? : CreateAbase ? CreateTable ??? ??????. 2) ?? ?? : ??, ????, ?? ? ??. 3) ?? ?? : ??, ?? ?? ? ?? ??. 4) ??? ?? : ??, ??? ?? ? ??? ??????. 5) ??? ?? : ??? ??, ??? ??? ??? ??????.

PHP?? ?????? ?? ??? ????? ?? ??? ??? ? ????. mysqli_connect_errno()? ???? ?? ??? ????. ?? ???? ???? mysqli_connect_error()? ??????. ??? ?? ???? ???? ???? ?????? ?? ??? ?? ???? ??? ? ?? ??????? ???? ??? ? ????.

Oracle? ?????? ?? ?? ? ??? ???? ??? ? ERP ???? ????????. 1. Oracle? ???????? ???? ??? ? ERP ???? ????? ??? ? ???? ?????. 2. OracleCloud? AWS? Azure? ???? IAA, PAAS ? SAAS ???? ?????. 3. E-BusinessSuite ? FusionApplications? ?? Oracle? ERP ???? ??? ??? ????? ? ??????.

MySQL? ?? ?? ??? ?????? ?? ?????, ?? ???? ???? ????? ???? ???? ? ?????. ?? ???? ????? ??, ?? ???, ?? ?? ? ?? ??? ?????. ??? ??? ??? ??, ??? ?? ? ?? ? ?? ??? ?? ?? ??? ?????. ???? ???? SQL ??, ??? ?? ? ??? ???? ??? ???? ??? ??, ??? ? ?? ? ??? ??? ?????.

MySQL? ? ?? ???? ? ??? ?? ???? ???? ?? ??, ??? ? ?? ???? ??? ????. 1) PostgreSQL? ???? MySQL? ??? ?? ? ?? ?? ?? ???? ? ? ?????. 2) Oracle? ??? ? MySQL? ?? ??? ??? ???? ?? ?? ???? ? ??? ????. 3) Microsoft SQL Server? ???? MySQL? ??? ??? ?? ????? ? ?????. 4) MongoDB? ?? MySQL? ??? ? ??? ? ???? ??? ? ?????.

MySQL? ???? ?? ???? ??? ????? ?????. 1.MySQL? ??? ???????? CRUD ??? SQL? ?????. 2. ??? ???? ?? ??? ????? ???????. 3. ??, ????, ?? ? ???? ??? ??? ??????. 4. Orderby, Where and Join? ??? ??? ??? ? ????. 5. ???? ??? ???? ??? ???? ?? ??? ???????. 6. ??? ???? ??? ??, ??? ??? ?? ?? ? ??? ????? ??? ?????.
