数据库02
这里只演示java-数据库的基本操作,在此基础上,再随便找本相关的参考书即可完成数据库其他基本操作。。。
package org.lxh.demo17.connectdemo;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
public class ResultSetDemo01 {
public static final String DBDRIVER = "com.mysql.jdbc.Driver";
public static final String DBURL = "jdbc:mysql://localhost:3306/mldn";
public static final String DBUSER = "root";
public static final String DBPASS = "xyzk123";
public static void main(String[] args) throws Exception{
Connection conn = null;
Statement stmt = null;
ResultSet rs = null;
String sql = "SELECT empno,ename,job FROM t_dept";
Class.forName(DBDRIVER);
conn = DriverManager.getConnection(DBURL, DBUSER, DBPASS);
stmt = conn.createStatement();
rs = stmt.executeQuery(sql);
while(rs.next()){
int empno = rs.getInt("empno");
String ename = rs.getString("ename");
String job = rs.getString("job");
System.out.println("编号" + empno + ";");
System.out.println("姓名" + ename + ";");
System.out.println("职业" + job + ";");
System.out.println(",,,,,,,,,,,,,,,,,,,,,,,,,,,,,");
}
rs.close();
stmt.close();
conn.close();
}
}