Hi everyone,
I'm doing a website in JSP. I'm using Tomcat 6 and have gotten the site talking to the backend file. However, when I go to add in a database connection, I have problems. This is my first time trying to connect to a SQL Server 2008 database. In the past I have used Oracle.
So I have the Context.xml file in the META-INF folder. This is an example of the file I had before with the Oracle information:
For SQL Server 2008:
I know the driverClassName will be "com.microsoft. sqlserver.jdbc. SQLServerDriver "
and that the url will be something like "jdbc:sqlserver ://localhost;Datab aseName=Pie"
But I'm not sure exactly what this file will look like. I need help getting the right information set.
So:
- Database name: Pie
- Typical connection string I would use in C#: connectionStrin g="Provider=SQL OLEDB;Data Source=XP_LAPTO P\SQLEXPRESS;In tegrated Security=SSPI;I nitial Catalog=Pie"
- I just use Windows Authentication to access SQL Server 2008 so would I set username and password to be my Windows login or just leave as blank?
Also: name="jdbc/myDatabase" - can this be any name so long as it matches up in the code?
Any help would be greatly appreciated! Thanks :)
I'm doing a website in JSP. I'm using Tomcat 6 and have gotten the site talking to the backend file. However, when I go to add in a database connection, I have problems. This is my first time trying to connect to a SQL Server 2008 database. In the past I have used Oracle.
So I have the Context.xml file in the META-INF folder. This is an example of the file I had before with the Oracle information:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<Context
override="true"
reloadable="true">
<Resource
auth="Container"
name="jdbc/myDatabase"
type="javax.sql.DataSource"
driverClassName="oracle.jdbc.OracleDriver"
username="lita"
password="123"
maxIdle="1"
maxWait="5000"
maxActive="3"
removeAbandoned="true"
url="jdbc:oracle:thin:@localhost:1521:XE"
removeAbandonedTimeout="0"
factory="org.apache.tomcat.dbcp.dbcp.BasicDataSourceFactory"/>
</Context>
For SQL Server 2008:
I know the driverClassName will be "com.microsoft. sqlserver.jdbc. SQLServerDriver "
and that the url will be something like "jdbc:sqlserver ://localhost;Datab aseName=Pie"
But I'm not sure exactly what this file will look like. I need help getting the right information set.
So:
- Database name: Pie
- Typical connection string I would use in C#: connectionStrin g="Provider=SQL OLEDB;Data Source=XP_LAPTO P\SQLEXPRESS;In tegrated Security=SSPI;I nitial Catalog=Pie"
- I just use Windows Authentication to access SQL Server 2008 so would I set username and password to be my Windows login or just leave as blank?
Also: name="jdbc/myDatabase" - can this be any name so long as it matches up in the code?
Code:
private Connection con;
Context init = new InitialContext();
Context ctx = (Context) init.lookup("java:comp/env");
DataSource ds = (DataSource) ctx.lookup("jdbc/myDatabase");
con = ds.getConnection();
Any help would be greatly appreciated! Thanks :)