Person.java
/**//*
* 创建日期 2005-3-17
*
*
*
*/
package com.faintbear;
/**//**
*
*
*
*
*/
public class Person {
private String empname="";
private String empno="";
public void setEmpName(String empname)
{
this.empname=empname;
}
public String getEmpName()
{
return this.empname;
}
public void setEmpNo(String empno)
{
this.empno=empno;
}
public String getEmpNo()
{
return this.empno;
}
}
DbConnect.java
package com.faintbear;
import java.util.*;
import java.sql.*;
/**//**
*
*
* 数据库连接和测试
*
*/
public class DbConnect {
public Connection conn;
private Statement stmt;
private PreparedStatement pstmt;
private String dburl="jdbc:oracle:thin:@192.168.41.16:1521:cc";
private String user="cc";
private String password="123456";
private String driver="oracle.jdbc.driver.OracleDriver";
public DbConnect() throws Exception
{
Class.forName(driver);
conn =DriverManager.getConnection(dburl,user,password);
stmt = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_UPDATABLE);
}
public Connection getConnection()
{
return conn;
}
public List getEmpNameList() throws Exception
{
String sql="select * from cus_emp_basic where rownum<10";
Connection conn=null;
Statement stmt=null;
ResultSet rst=null;
ArrayList resultlist = new ArrayList();
try
{
rst=(new DbConnect()).stmt.executeQuery(sql);
while (rst.next())
{
Person person = new Person();
person.setEmpNo(rst.getString("emp_no"));
person.setEmpName(rst.getString("emp_name"));
resultlist.add(person);
}
}finally
{
if(rst!=null)rst.close();
if(stmt!=null)stmt.close();
if(conn!=null)conn.close();
}
return resultlist;
}
public static void main(String []args) throws Exception
{
DbConnect dbc = new DbConnect();
List l1=(dbc.getEmpNameList());
for(int i=0;i<l1.size();i++)
{
Person person1=(Person)l1.get(i);
System.out.println("person"+i+"="+person1.getEmpName()+" "+"empno="+person1.getEmpNo());
}
}
}
本文出自 51CTO.COM技术博客
/**//*
* 创建日期 2005-3-17
*
*
*
*/
package com.faintbear;
/**//**
*
*
*
*
*/
public class Person {
private String empname="";
private String empno="";
public void setEmpName(String empname)
{
this.empname=empname;
}
public String getEmpName()
{
return this.empname;
}
public void setEmpNo(String empno)
{
this.empno=empno;
}
public String getEmpNo()
{
return this.empno;
}
}
DbConnect.java
package com.faintbear;
import java.util.*;
import java.sql.*;
/**//**
*
*
* 数据库连接和测试
*
*/
public class DbConnect {
public Connection conn;
private Statement stmt;
private PreparedStatement pstmt;
private String dburl="jdbc:oracle:thin:@192.168.41.16:1521:cc";
private String user="cc";
private String password="123456";
private String driver="oracle.jdbc.driver.OracleDriver";
public DbConnect() throws Exception
{
Class.forName(driver);
conn =DriverManager.getConnection(dburl,user,password);
stmt = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_UPDATABLE);
}
public Connection getConnection()
{
return conn;
}
public List getEmpNameList() throws Exception
{
String sql="select * from cus_emp_basic where rownum<10";
Connection conn=null;
Statement stmt=null;
ResultSet rst=null;
ArrayList resultlist = new ArrayList();
try
{
rst=(new DbConnect()).stmt.executeQuery(sql);
while (rst.next())
{
Person person = new Person();
person.setEmpNo(rst.getString("emp_no"));
person.setEmpName(rst.getString("emp_name"));
resultlist.add(person);
}
}finally
{
if(rst!=null)rst.close();
if(stmt!=null)stmt.close();
if(conn!=null)conn.close();
}
return resultlist;
}
public static void main(String []args) throws Exception
{
DbConnect dbc = new DbConnect();
List l1=(dbc.getEmpNameList());
for(int i=0;i<l1.size();i++)
{
Person person1=(Person)l1.get(i);
System.out.println("person"+i+"="+person1.getEmpName()+" "+"empno="+person1.getEmpNo());
}
}
}
本文出自 51CTO.COM技术博客