import java.sql.*;
import java.util.*;
class Sql
{
public static void main(String[] args)
{
try
{
String query="select * from orders";
String URL="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=Northwind";
String userName = "sa";
String userPwd = "14579";
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
Connection conn=DriverManager.getConnection(URL,userName,userPwd);
Statement stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
ResultSet rs=stmt.executeQuery(query);
int i=0;
for(i=0;i<10;i++)
{
rs.next();
System.out.println(rs.getString(1));
}
//SQLServer2K自带的样例数据库Northwind中,表Orders有多于10条,可能上百条记录,所以只列10条!
}
catch(Exception e)
{
System.out.println(e.getMessage());
}
}
}
结果:
posted on 2007-05-25 22:28
jadmin 阅读(85)
评论(0) 编辑 收藏