try{ Class.forName("com.mysql.jdbc.Driver"); } catch(Exception e){}
Connection con; String uri = "jdbc:mysql://192.168.100.1:3306/students?user=root&password=&useSSL=true"; try{ con = DriverManager.getConnection(uri); //鏈接代碼 } catch(SQLException e){ System.out.println(e); }
Connection con; String uri = "jdbc:mysql:// 192.168.100.1:3306/students? useSSL=true"; String user ="root"; String password =""; try{ con = DriverManager.getConnection(uri,user,password); //鏈接代碼 } catch(SQLException e){ System.out.println(e); }
String uri = "jdbc:mysql://localhost/students?useSSL=true&characterEncoding=utf-8"; con = DriverManager.getConnection(uri, "root",""); //鏈接代碼
try{ Statement sql=con.createStatement(); } catch(SQLException e ){}
二、這個對象就能夠調用相應的方法實現對數據庫中表的查詢和修改,並將查詢結果存放在一個ResultSet類聲明的對象html
ResultSet rs = sql.executeQuery("SELECT * FROM students");
也就是說SQL查詢語句對數據庫的查詢操做將返回一個ResultSet對象,ResultSet對象是按「列」(字段)組織的數據行構成。java
con.close();
此後,程序將沒法獲取ResultSet對象中的數據mysql
Statement stmt = con.createStatement(int type ,int concurrency);
條件和排序查詢:
1. where子語句
通常格式:git
select 字段 from 表名 where 條件
2. 排序 用order by子語句對記錄排序
select * from mess where name like '%林%' order by name
update 表 set 字段 = 新值 where <條件子句>
insert into 表(字段列表) values (對應的具體的記錄) 或 insert into 表 values (對應的具體的記錄)
delete from 表名 where <條件子句>
JDBC事務處理步驟:
1.用setAutoCommit(booean b)方法關閉自動提交模式
2.用commit()方法處理事務
3.用rollback()方法處理事務失敗正則表達式
問題1解決方案:參考JDBC各類數據庫鏈接方式sql
問題1:在按照配套PPT使用windows安裝MySqlt初始data時出錯
數據庫
問題1解決方案:進入C:/windows/system32 ,找到cmd,經過管理員身份運行cmd,在mysql目錄的bin子目錄下輸入mysqld --initialize-insecure能夠初始化成功windows
(statistics.sh腳本的運行結果截圖)數組
解析:C項:\b\w{6}\b 匹配恰好6個字符的單詞。F項: IP地址中每一個數字都不能大於255,該表達式忽略了這個約束條件。正確的是((2[0-4]\d|25[0-5]|[01]?\d\d?).){3}(2[0-4]\d|25[0-5]|[01]?\d\d?)。服務器
代碼中值得學習的或問題:
代碼中文件分類簡潔
很認真
本週學習瞭如何安裝和使用MySQL數據庫管理系統,創建鏈接,關閉連接,以及查詢、添加、刪除等各類操做
代碼行數(新增/累積) | 博客量(新增/累積) | 學習時間(新增/累積) | 重要成長 | |
---|---|---|---|---|
目標 | 5000行 | 25篇 | 400小時 | |
第一週 | 235/235 | 1/1 | 15/15 | |
第二週 | 224/459 | 2/3 | 15/30 | |
第三週 | 443/902 | 1/4 | 15/73 | |
第四周 | 577/1479 | 2/6 | 17/90 | |
第五週 | 1222/2360 | 1/7 | 14/104 | |
第六週 | 1527/3294 | 1/8 | 14/118 | |
第七週 | 591/3883 | 1/9 | 14/132 |