-
大小: 1.97MB文件類(lèi)型: .rar金幣: 2下載: 0 次發(fā)布日期: 2023-09-21
- 語(yǔ)言: Java
- 標(biāo)簽:
資源簡(jiǎn)介
java數(shù)據(jù)庫(kù) java數(shù)據(jù)庫(kù) java數(shù)據(jù)庫(kù) java數(shù)據(jù)庫(kù) java數(shù)據(jù)庫(kù) java數(shù)據(jù)庫(kù) java數(shù)據(jù)庫(kù) java數(shù)據(jù)庫(kù) java數(shù)據(jù)庫(kù) java數(shù)據(jù)庫(kù) java數(shù)據(jù)庫(kù) java數(shù)據(jù)庫(kù)

代碼片段和文件信息
package?test;
import?java.sql.DriverManager;
import?java.sql.SQLException;
import?com.mysql.jdbc.Connection;
import?com.mysql.jdbc.Statement;
public?class?conn?{??????????????????????????????????//創(chuàng)建數(shù)據(jù)庫(kù)連接類(lèi)。
public?static?void?main(String?args[])?{?????????????//主方法。
String?dbUrl?=?“jdbc:mysql://localhost:3306/student“;//定義連接數(shù)據(jù)庫(kù)的url。
String?dbUser?=?“root“;?????????????????????//定義登錄數(shù)據(jù)庫(kù)的用戶(hù)名。
String?dbPwd?=?“esoft“;?????????????????????//定義等譯數(shù)據(jù)庫(kù)的密碼。
Connection?conn?=?null;????????????????????//創(chuàng)建Connection類(lèi)的對(duì)象conn,并讓其指向空。
Statement?stmt?=?null;??????????????????????//創(chuàng)建Statement類(lèi)的對(duì)象stmt對(duì)象。
try?{
Class.forName(“com.mysql.jdbc.Driver“);??//加載驅(qū)動(dòng)。
}?catch?(ClassNotFoundException?e)?{
e.printStackTrace();
}
String?Str?=?“create?table?course?“?+?“(id?INTEGERcno?VARCHAR(32)cname?FLOAT)“;
try?{
conn?=?(Connection)?DriverManager.getConnection(dbUrl?dbUser
dbPwd);
System.out.println(“獲取和MySQL數(shù)據(jù)庫(kù)的一個(gè)連接!“);
stmt?=?(Statement)?conn.createStatement();
System.out.println(“創(chuàng)建一個(gè)語(yǔ)句對(duì)象!“);
stmt.executeUpdate(Str);
System.out.println(“執(zhí)行創(chuàng)建表的SQL語(yǔ)句!“);
System.out.println(“在student數(shù)據(jù)庫(kù)中創(chuàng)建了表course!“);
}?catch?(SQLException?e)?{
e.printStackTrace();
}?finally?{
try?{
stmt.close();
conn.close();
}?catch?(SQLException?e)?{
e.printStackTrace();
}
}
}
}
?屬性????????????大小?????日期????時(shí)間???名稱(chēng)
-----------?---------??----------?-----??----
?????文件????????414??2009-02-25?14:02??第20章\例20-1\TestDataba
?????文件????????315??2009-02-25?14:02??第20章\例20-1\TestDataba
?????文件???????1016??2009-02-25?14:02??第20章\例20-1\TestDataba
?????文件???????1485??2009-02-25?14:03??第20章\例20-1\TestDataba
?????文件????????834??2009-02-25?14:02??第20章\例20-1\TestDataba
?????文件?????????39??2009-02-25?14:02??第20章\例20-1\TestDataba
?????文件???????1976??2009-02-25?14:02??第20章\例20-1\TestDataba
?????文件?????397032??2009-02-25?14:02??第20章\例20-1\TestDataba
?????文件????????375??2009-02-25?14:02??第20章\例20-1\TestDataba
?????文件????????414??2009-02-25?14:11??第20章\例20-2\TestConnectDataba
?????文件????????330??2009-02-25?14:11??第20章\例20-2\TestConnectDataba
?????文件???????1237??2009-02-25?14:11??第20章\例20-2\TestConnectDataba
?????文件???????1576??2009-02-25?14:11??第20章\例20-2\TestConnectDataba
?????文件???????1063??2009-02-25?14:11??第20章\例20-2\TestConnectDataba
?????文件????????479??2009-02-25?14:11??第20章\例20-2\TestConnectDataba
?????文件??????20868??2009-02-25?14:11??第20章\例20-2\TestConnectDataba
?????文件??????41524??2009-02-25?14:11??第20章\例20-2\TestConnectDataba
?????文件???????2280??2009-02-25?14:11??第20章\例20-2\TestConnectDataba
?????文件?????????39??2009-02-25?14:11??第20章\例20-2\TestConnectDataba
?????文件???????2264??2009-02-25?14:11??第20章\例20-2\TestConnectDataba
?????文件???????1702??2009-02-25?14:11??第20章\例20-2\TestConnectDataba
?????文件????????876??2009-02-25?14:11??第20章\例20-2\TestConnectDataba
?????文件??????23773??2009-01-22?15:47??第20章\例20-2\TestConnectDataba
?????文件?????397032??2009-02-25?14:11??第20章\例20-2\TestConnectDataba
?????文件?????413170??2009-01-22?15:47??第20章\例20-2\TestConnectDataba
?????文件????????838??2009-02-25?14:11??第20章\例20-2\TestConnectDataba
?????文件????????414??2009-02-25?14:15??第20章\例20-3\TestConnectDataba
?????文件????????330??2009-02-25?14:15??第20章\例20-3\TestConnectDataba
?????文件???????1237??2009-02-25?14:15??第20章\例20-3\TestConnectDataba
?????文件???????1576??2009-02-25?14:15??第20章\例20-3\TestConnectDataba
............此處省略51個(gè)文件信息
評(píng)論
共有 條評(píng)論