-
大小: 2.30KB文件類型: .zip金幣: 1下載: 0 次發(fā)布日期: 2021-02-01
- 語言: Java
- 標(biāo)簽:
資源簡介
Java入門-修改數(shù)據(jù)庫(實(shí)例78).zip
代碼片段和文件信息
import?java.sql.*;
public?class?UpdateDemo{
private?String?dbURL=“jdbc:odbc:example“; //?數(shù)據(jù)庫標(biāo)識名
private?String?user=“devon“; //?數(shù)據(jù)庫用戶
private?String?password=“book“; //?數(shù)據(jù)庫用戶密碼
public?UpdateDemo(){
try {
Class.forName(“sun.jdbc.odbc.JdbcOdbcDriver“);??//加載驅(qū)動器
Connection?con=DriverManager.getConnection(dbURLuserpassword);?//獲取連接
String?sqlStr=“select?*?from?users“;?//SQL查詢語句
Statement?st=con.createStatement();?//獲取PreparedStatement對象
ResultSet?rs=st.executeQuery(sqlStr);?//執(zhí)行查詢
String?namesexemail;?//查詢結(jié)果
int?age;
System.err.println(“更新前數(shù)據(jù)“);
while?(rs.next()){?//遍歷ResultSet
name=rs.getString(“name“);?//獲取數(shù)據(jù)
age=rs.getInt(“age“);
sex=rs.getString(“sex“);
email=rs.getString(“email“);
System.out.println(“Name:?“
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件????????2265??2004-07-21?18:03??UpdateDemo.class
?????文件????????1925??2004-06-11?00:28??UpdateDemo.java
評論
共有 條評論