import java.sql.*;
public class sqlOperate
{
private Connection con;
public void connection()
{
try
{
String url = "jdbc:odbc:LocalServer";
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con = DriverManager.getConnection(url,"sa","");
}
catch(Exception e)
{
System.out.println("没有连接!");
}
}
public void select()
{
try
{
Statement sel = con.createStatement();
ResultSet rs;
rs = sel.executeQuery("select * from student");
while(rs.next())
{
System.out.println(rs.getString("sno")+" "+rs.getString("age"));
}
}
catch(Exception e)
{
System.out.println("查询出错");
}
}
public static void main(String[] args)
{
sqlOperate a = new sqlOperate();
a.connection();
a.select();
}
}
posted on 2007-03-24 11:04
heyibofly 阅读(109)
评论(0) 编辑 收藏