JSP动态网页中如何向SQL Server 2000 数据库中插入数据

2024-12-29 02:16:21
推荐回答(1个)
回答1:

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();