大四下半學期,草草搞完了畢業設計,出去面試了,
好多家都要求懂JSP的,我就開始學JSP看看,
一開始就被難住了,JDBC串連SQL server 的問題,試了一天都不能成功,後來償試這樣就行了!!
1、下載Microsoft SQL Server 2000 Service Pack 3a並安裝,SQL請選用混和安裝模式!!!
http://www.microsoft.com/downloads/details.aspx?FamilyId=90DCD52C-0488-4E46-AFBF-ACACE5369FA3&displaylang=zh-cn
2、下載SQL Server 2000 Driver for JDBC Service Pack 3
http://www.microsoft.com/downloads/details.aspx?FamilyId=07287B11-0502-461A-B138-2AA54BFDC03A&displaylang=en
3、運行時關閉防火牆
4、可以測試下串連 建立一個JSP檔案 寫代碼
<%@ page contentType="text/html;charset=GB2312" %>
<%@ page import="java.sql.*" %>
<HTML>
<title>test sql server</title>
<head></head>
<BODY>
<%
try
{out.print("裝載資料庫驅動程式...");
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance();
out.print("裝載資料庫驅動程式成功...");
String url = "jdbc:microsoft:sqlserver://ACER-81ABD5BF54:1433;DatabaseName=db_Job";
Connection conn = DriverManager.getConnection(url,"sa","sa");
out.print("串連資料庫成功!");
out.print("開始資料庫查詢... ");
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery("SELECT * from tb_admin");
out.print("查詢資料庫成功! ");
}
catch(Exception e){
out.print("資料庫操作失敗!" + e.toString());
}
%>
</BODY>
</HTML>