JSP, JDBC and MS SQL Server March 28 2007
A quick post to illustrate how to connect to an SQL Server instance through JSP/Java.
1. Get the JDBC driver for SQL Server from the microsoft web site. As of this posting it is version 1.1. (Just search for “JDBC SQL Server Driver”
2. Put the driver (the JAR file) into the Tomcat lib directory
3. Restart Tomcat
4. In your JSP code, add the line to include the JDBC library for SQL Server :
< %@ page import="java.sql.*,com.microsoft.sqlserver.jdbc.*" %>
5. Now add the sweet sweet inards
< %
CallableStatement cstmt = null;
ResultSet rs = null;
Connection con = null;
SQLServerDataSource ds = new SQLServerDataSource();
ds.setUser(”MarketingWeb”);
ds.setPassword(”*******”);
ds.setServerName(”HQSQL1″);
ds.setPortNumber(1433);
ds.setDatabaseName(”MarketingWebSite”);
try {
con = ds.getConnection();
// Execute a …
