Posted on 2008-06-25 22:26
陌上尘 阅读(336)
评论(0) 编辑 收藏 所属分类:
JAVA-J2EE
import java.sql.*;
public class Access{
public static void main(String args[]){
Connection con;
Statement sql; //声明Statement对象
ResultSet rs;
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}
catch(ClassNotFoundException e){
System.out.println(""+e);
}
try{
con=DriverManager.getConnection("jdbc:odbc:redsun","","");
sql=con.createStatement();
rs=sql.executeQuery("Select * FROM member");
while(rs.next()){
String name=rs.getString(1); //获得数据库第一列
String sex=rs.getString(2);
System.out.println("姓名:"+name); //输出信息
System.out.println("性别:"+sex);
}
con.close();
}
catch(SQLException el){}
}
}