In the second half of my senior year, I finished my graduation project and went out for an interview,
Many of them want to understand JSP, so I started to learn JSP,
At the beginning, it was hard to get stuck. The problem of connecting to SQL Server through JDBC was that it could not be successful after a day. Then it would be worth the effort !!
1. Download and install Microsoft SQL Server 2000 Service Pack 3A. Select the hybrid installation mode for SQL !!!
Http://www.microsoft.com/downloads/details.aspx? Familyid = 90dcd52c-0488-4e46-afbf-ace5107fa3 & displaylang = ZH-CN
2. Download 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. Disable the firewall during running
4. Test the connection and create a new JSP file to write code.
<% @ Page contenttype = "text/html; charset = gb2312" %>
<% @ Page import = "Java. SQL. *" %>
<HTML>
<Title> test SQL server </title>
<Head> <Body>
<%
Try
{Out. Print ("load the database driver ...");
Class. forname ("com. Microsoft. JDBC. sqlserver. sqlserverdriver"). newinstance ();
Out. Print ("database driver loaded successfully ...");
String url = "JDBC: Microsoft: sqlserver: // ACER-81ABD5BF54: 1433; databasename = db_job ";
Connection conn = drivermanager. getconnection (URL, "sa", "sa ");
Out. Print ("connected to the database! ");
Out. Print ("START database query ...");
Statement stmt = conn. createstatement ();
Resultset rs = stmt.exe cutequery ("select * From tb_admin ");
Out. Print ("the database is queried successfully! ");
}
Catch (exception e ){
Out. Print ("database operation failed! "+ E. tostring ());
}
%>
</Body>
</Html>