Make sure you include the finally block to close your connection.
Add the following after the catch block
finally {
try { if(connection != null) connection.close(); }
catch(Exception e) {}
}
----- Original Message -----
From: "Andrew Bruno" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Wednesday, August 15, 2001 8:45 PM
Subject: Re: DSN less connection for SQLServer/Oracle in java
Hello SriHari,
I have attached a sample jsp file which pulls out a list of all the
databases defined
on your MS SQL server using the freetds.org type4 driver.
I wrote this jsp just for testing the environment when I deploy a web
app.
Goodluck, Andrew
<%--
FileName: testfreetdsjdbctype4driver.jsp
Purpose: To test the FREEDTS type 4 driver on a windows 2000 server, MS
SQL 7.0 and
TOMCAT 4.0 environement before deploying.
References:
http://www.jguru.com/faq/view.jsp?EID=268823
http://www.freetds.org/faq.html#jdbc test
http://www-106.ibm.com/developerworks/library/jdbc-objects/
Driver Name:InternetCDS Type 4 JDBC driver for MS SQLServer
Driver Version:0.2 1
JDBC Driver properties:
freetds_jdbc.snapshot.2_0.jar - 9 March 2001, 2:04 AM
downloaded from
ftp://freetds.internetcds.com/pub/freetds_jdbc/
Copy the freetdsxxx.jar file into %CATALINA_HOME%\lib amd restart
Tomcat.
This file has been tested with MS SQL Server 7.0, on windows 2000
server,
using Apache Tomcat/4.0-b6.
It basically outputs a table showing all the databases defined on a
server
--%>
<%@ page info="database handler"%>
<%@ page import="java.io.*"%>
<%@ page import="java.util.*"%>
<%@ page import="java.sql.*"%>
<%@ page import="javax.servlet.*"%>
<%@ page import="javax.servlet.http.*"%>
<HTML>
<BODY>
<TABLE BORDER=1>
<%
try {
String server="localhost"; //hostname or IP address
of sql server
String database="master"; //name of database
String sqlport="1433"; //ms sql default port
String user="sa"; //database user
String password="something"; //database password
String url = "jdbc:freetds:sqlserver://" + server + ":" +
sqlport + "/" + database;
//LOAD type 4 JDBC driver from freedts.org
//make sure jar file located in %CATALINA_HOME%\lib
Class.forName("com.internetcds.jdbc.tds.Driver");
Connection connection = DriverManager.getConnection(url, user,
password);
//to get the driver version
DatabaseMetaData conMD = connection.getMetaData();
out.println("<BR>Driver Name:" + conMD.getDriverName());
out.println("<BR>Driver Version:" + conMD.getDriverVersion() +
"<P>");
//create a statement
Statement st = connection.createStatement();
//execute a query
ResultSet rs = st.executeQuery("SELECT * FROM
master.dbo.sysdatabases");
//Print the column names of the returned table
out.println("<TR>");
for (int j = 1; j <= rs.getMetaData().getColumnCount(); j++) {
// lets print the column names
out.println("<TD><B>" +
rs.getMetaData().getColumnName(j));
}
//Display the table rows
while (rs.next()) {
out.println("<TR>");
for (int j = 1; j <= rs.getMetaData().getColumnCount();
j++) {
out.println("<TD>" + rs.getObject(j));
}
}
//close the objects
st.close();
connection.close();
} catch (Exception e) { e.printStackTrace(); }
%>
</TABLE>
</BODY>
</HTML>
=========================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff
JSP-INTEREST".
For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST
DIGEST".
Some relevant FAQs on JSP/Servlets can be found at:
http://java.sun.com/products/jsp/faq.html
http://www.esperanto.org.nz/jsp/jspfaq.html
http://www.jguru.com/jguru/faq/faqpage.jsp?name=P
http://www.jguru.com/jguru/faq/faqpage.jsp?name=rvlets
===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST DIGEST".
Some relevant FAQs on JSP/Servlets can be found at:
http://java.sun.com/products/jsp/faq.html
http://www.esperanto.org.nz/jsp/jspfaq.html
http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets