<%@ 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>
