<%@ page language="java" import="java.sql.*" pageEncoding="UTF-8"%> <html> <head> <title>插入界面</title> </head> <body> <% String driverName = "com.microsoft.sqlserver.jdbc.SQLServerDriver"; //加载JDBC驱动 String dbURL = "jdbc:sqlserver://localhost:1433; DatabaseName=JSPTest"; //连接服务器和数据库 String userName = "sa"; //默认用户名 String userPwd = "123456"; //密码 Class.forName(driverName); Connection Conn = DriverManager.getConnection(dbURL, userName, userPwd); System.out.println("Connection Successful!"); String sql="Insert into regist(ID,password) values(?,?)"; PreparedStatement pstmt=Conn.prepareStatement(sql); pstmt.setString(1, "201504"); pstmt.setInt(2, 111); int n=pstmt.executeUpdate(); if(n==1){%>数据插入成功!<br><%} else{%>数据插入失败!<br><%} %> </body> </html>