日期:2014-05-17 浏览次数:20598 次
package util;
import java.sql.*;
public class DBConnection {
@SuppressWarnings("unused")
public static void main(String[] args) {
String url = "jdbc:oracle:thin:@localhost:1521:orcl";
String user = "scott";
String password = "tiger";
Connection con;
Statement stmt;
try {
Class.forName("oracle.jdbc.driver.OracleDriver");
con = DriverManager.getConnection(url, user, password);
stmt = con.createStatement();
con.close();
System.out.println("connect-ok!@!!");
} catch (Exception e) {
// TODO: handle exception
System.out.println(e.getMessage());
}
}
}
package dao;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import javax.servlet.jsp.jstl.sql.Result;
//import util.ConnectionUtil;
import vo.EmpVO;
public class EmpDao {
Connection conn =null;
PreparedStatement pstmt = null;
Result rs = null;
/** public EmpDao() throws SQLException{
conn = ConnectionUtil.getConnection();
}**/
public ArrayList<EmpVO> selectEmp() throws SQLException{
ArrayList<EmpVO> list = new ArrayList<EmpVO>();
StringBuffer sql = new StringBuffer();
sql.append("select empo,ename,job,mgr,hirdate,sal,comm,deptno from emp");
PreparedStatement pstmt = conn.prepareStatement(sql.toString());
ResultSet rs = pstmt.executeQuery();
while(rs.next()){
EmpVO vo = new EmpVO();
vo.setEmpno(rs.getInt("empno"));
vo.setEname(rs.getString("ename") );
vo.setJob(rs.getString("job"));
vo.setMgr(rs.getInt("mgr"));
vo.setHiredate(rs.getString("hiredate"));
vo.setSal(rs.getFloat("sal"));
vo.setComm(rs.getFloat("comm"));
vo.setDeptno(rs.getInt("deptno"));
list.add(vo);
}
if(rs!=null) rs.close();
if(pstmt !=null) pstmt.close();
if(conn !=null) conn.close();
return list;
}
}
package vo;
public class EmpVO {
private int empno,mgr,deptno;
private String ename,job,hiredate;
private float sal,comm;
public int getEmpno() {
return empno;
}
public void setEmpno(int empno) {
this.empno = empno;
}
public int getMgr() {
return mgr;
}
public void setMgr(int mgr) {
this.mgr = mgr;
}
public int getDeptno() {
return deptno;
}
public void setDeptno(int deptno) {