String sDBDriver = "com.microsoft.jdbc.sqlserver.SQLServerDriver";
String sConnStr = "jdbc:microsoft:sqlserver://127.0.0.1:1433;DatabaseName=数据库名";
Connection conn = null;
ResultSet rs = null;
Class.forName(sDBDriver);
conn = DriverManager.getConnection(sConnStr,"登录数据库的用户名","登录数据库密码");
Statement stmt = conn.createStatement();
String sql="select * from t_user";
rs = stmt.executeQuery(sql);
while(rs.next()){
out.println(rs.getString("username"));
out.println(rs.getString("password"));
out.println("
");
}
rs.close();
conn.close();
stmt.close();