MySQL數據庫 啓動 命令行進入MySQL安裝目錄的bin目錄,輸入mysqld--initialize-insecure 做用是初始化data目錄,並受權一個無密碼的root用戶 roo用戶 MySQL數據庫服務器的root用戶是默認沒有密碼的,修改密碼使用以下命令 mysqladmin -u root -p password JDBC 專門用於操做數據庫的API。 鏈接數據庫 1.加載JDBC-數據庫驅動。 try{ Class. forName("com.mysql.jdbc.Driver"); } catch(Exception e){} 鏈接數據庫 Connection con; String uri = "jdbc:mysql://192.168.100.1:3309/student?user=root&password=&useSSL=true"; try{ con = DriverManager.getConnection(uri); } catch(SQLException e){ System.out.println(e); } 若是數據庫的表中的記錄有漢字,那麼創建鏈接時須要額外多傳一個參數characterEncoding取值爲gb2312或utf-8 向數據庫發送SQL查詢語句 try {Statement sql=con.createStatement(); } catch(SQLException e) {} 處理查詢結果 返回一個ResultSet對象 ResultSet rs = sql.executeQuery{"SELCET * FROM student"); 關閉連接 con.close(); 順序查詢 next()移到下一個數據行 條件與排序查詢 通常格式:select 字段 from 表名 where 條件 更新,添加與刪除操做 更新:update 表 set 字段 = 新值 where <條件子句> 添加:insert into 表 values 刪除:delete from 表名 where <條件子句>
碼雲連接:https://gitee.com/sq943997011/BESTI.IS.Java2018mysql
腳本運行截圖:
git