7-79 N個數求和 (20分)
阿新 • • 發佈:2020-12-12
JDBC
對jdbc載入到執行關閉資源的六個過程。
//1.載入驅動
Class.forName("com.mysql.jdbc.Driver");
//2.獲取資料庫連線物件(3個方式)
Connection coon = DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/test", "root", "admin");
//或者
Connection coon = DriverManager.getConnection ("jdbc:mysql://127.0.0.1:3306/test?user=root&password=admin");
//或者
Properties info=new Properties();
info.put("user","root");
info.put("password","admin");
Connection coon = DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/test",info);
//3.獲取能夠處理sql語句的物件
Statement stat=coon.createStatement();
//4.執行sql語句(當執行select時為true,其他時候都為false)
boolean f = stat.execute("insert into user(username,password,nickname) values ('soft123','soft123456','李四')");
//5.處理結果
System.out.println("執行結果:"+f);
//6.關閉資源
stat.close();
coon.close();