數據庫內容
import java
// DataSource 數據源名稱DSN
private String DatabaseConnStr = "jdbc:mysql://localhost:
+ "
this
} public String getDatabaseDriver() {
return (this
} public void setDatabaseConnStr(String ConnStr) {
this
} public String getDatabaseConnStr() {
return (this
} public database_manage() {// 構造函數連接數據庫
try {
Class
} catch (java
System
System
}
}
public ResultSet query(String sql) {// 查詢數據庫
rs = null;
try {
conn = DriverManager
"jdbc:mysql://localhost:
"root"
Statement stmt = conn
rs = stmt
} catch (SQLException ex) {
System
System
}
return rs;
} public int update_database(String sql) {// 更新或插入數據庫int num =
try {
conn = DriverManager
"jdbc:mysql://localhost:
"root"
Statement stmt = conn
num = stmt
} catch (SQLException ex) {
System
System
} CloseDataBase();
return num; } public void CloseDataBase() {// 關閉數據庫
try {
conn
} catch (Exception end) {
System
System
}
} } class people {
private String uid;
private String name;
private String banji;
private int score; public people() {
} public people(String uid
this
this
this
} public people(String uid
this
this
this
this
} public String getUid() {
return uid;
} public void setUid(String uid) {
this
} public String getName() {
return name;
} public void setName(String name) {
this
} public String getBanji() {
return banji;
} public void setBanji(String banji) {
this
} public int getScore() {
return score;
} public void setScore(int score) {
this
} } public class manage { private people[] people_array
+ "
// String sql
db_obj
} public void update_people(String uid
+ "
database_manage db_obj = new database_manage();
db_obj
database_manage db_obj = new database_manage();
// String adminid=null;
String uid_new
uid_new = null;
name = null;
banji = null;
String sql_query = "select * from people where uid=
ResultSet rs = db_obj
if (rs
uid_new = rs
name = rs
banji = rs
}
} catch (Exception e) {
e
}
people new_people = new people(uid_new
return new_people;
} public people[] query_people_byscore(int score) {
database_manage db_obj = new database_manage();
String uid_new
uid_new = null;
name = null;
banji = null;
int score_new =
String sql_query = "select * from people where score=" + score;// sql查詢語句
try {
ResultSet rs = db_obj
int num =
ResultSet rs_new = rs;
while (rs_new
num++;
}
// System
people_array
int i =
rs
while (rs
uid_new = rs
name = rs
banji = rs
score_new = rs
people_array
i++;
}
} catch (Exception e) {
e
}
return people_array
}
public static void main(String args[]) {
/*
* people new_people=new people();
*
* manage mr=new manage(); //mr
*
* new_people=mr
* println(""+new_people
* mr
*
* new_people=mr
*
* System
* ));
*/
manage mr = new manage();
// mr
people[] people_array;// 聲明對象數組
people_array = mr
int num =
num = people_array
for (int i =
System
+ people_array[i]
+ people_array[i]
+ people_array[i]
}
}
}
程序運行結果
From:http://tw.wingwit.com/Article/program/Java/JSP/201311/20030.html