package cn.itcast.jdbc;
import JDBCUtils.JDBCUtils;
import java.sql.*;
public class JDBCUtilsDemo {
public static void main(String[] args) {
Connection conn = null;
Statement state = null;
ResultSet rs = null;
try {
conn = JDBCUtils.getConncetion();
state = conn.createStatement();
rs = state.executeQuery("select*from emp");
while (rs.next()) {
int id = rs.getInt("id");
String ename = rs.getString("ename");
int jobId = rs.getInt("job_id");
int mgr = rs.getInt("mgr");
Date joinDate = rs.getDate("joindate");
double salary = rs.getDouble("salary");
double bonus = rs.getDouble("bonus");
System.out.println(id + "\t" + ename + "\t" + jobId + "\t" + mgr + "\t" + joinDate + "\t" + salary + "\t" + bonus);
}
} catch (SQLException e) {
e.printStackTrace();
} finally {
JDBCUtils.close(rs, state, conn);
}
}
}
|
|