標籤:成功 external nec update aries 1.4 rman dex config
1.首先安裝MySQL,把bin目錄添加到path 環境變數
2.修改 sql 登入名稱為123456.update mysql.user set authentication_string=password(‘123456‘) where user=‘root‘
3.mysql 官網下載mysql-connector-java-5.1.44,項目屬性build path->configure build path ->libraries ->Add external Jars添加 mysql-connector-java-5.1.44檔案夾裡面的mysql-connector-java-5.1.44-bin.jar組件
4.開啟mysql 服務登入 ,展示資料庫,添加表格
net start mysql
mysql -uroot -p123456
show databases
use abc
5串連代碼
import java.sql.*;
public class MainDemo {
public static void main(String[] args){
try{
//調用Class.forName()方法載入驅動程式
Class.forName("com.mysql.jdbc.Driver");
System.out.println("成功載入MySQL驅動!");
}catch(ClassNotFoundException e1){
System.out.println("找不到MySQL驅動!");
e1.printStackTrace();
}
String url="jdbc:mysql://localhost:3306/abc"; //JDBC的URL
Connection conn;
try {
conn = DriverManager.getConnection(url, "root","123456");
//建立一個Statement對象
Statement stmt = conn.createStatement(); //建立Statement對象
System.out.print("成功串連到資料庫!");
String sql="select * from abcbiao1";
ResultSet rs=stmt.executeQuery(sql);
System.out.println("編號"+"\t"+"姓名"+"\t"+"年齡");
while(rs.next())
{
System.out.print(rs.getInt(1)+"\t");
System.out.print(rs.getString(2)+"\t");
System.out.println();
}
rs.close();
stmt.close();
conn.close();
} catch (SQLException e){
System.out.println("串連不成功");
e.printStackTrace();
}
}
}
java連結MySQL