----------------------------------------------------------------
BEFORE YOU POST, search the faq at <http://java.apache.org/faq/>
WHEN YOU POST, include all relevant version numbers, log files,
and configuration files. Don't make us guess your problem!!!
----------------------------------------------------------------
I don't know if this applies to your situation, but running apps under
Windows NT 4, I have noticed similar behaviors depending on whether the data
source is a User DSN or a System DSN. And if you have it defined both ways,
then services can behave differently from normal apps. Perhaps your problem
is not JServ related.
Regards,
.... Bob Kimble
-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED]] On Behalf Of Peter Bosch
Sent: Wednesday, May 24, 2000 4:24 PM
To: [EMAIL PROTECTED]
Subject: JDBC servlet failing. "Identical" app works.
----------------------------------------------------------------
BEFORE YOU POST, search the faq at <http://java.apache.org/faq/>
WHEN YOU POST, include all relevant version numbers, log files,
and configuration files. Don't make us guess your problem!!!
----------------------------------------------------------------
Running the following:
Win2K Advanced Server.
SQL Server 7.
JDK 1.3
Apache/1.3.12 (Win32)
ApacheJServ/1.1
An application that reads a database through jdbc:odbc driver works, while
the same
code in a servlet does not. The attempt to process the statement resulted in
a bad
object being requested in the database. I'd checked paths, classpaths and
other
config items, and then found the problem. (BUT I STILL WANT TO KNOW WHY.)
As it turned out, JDBC via an application opened the connection with the
catalog as
specified in the ODBC administrator.
But when an ODBC connection was opened through a servlet running in JServ,
the
connection was opened with the default catalog. I had to explicitly set it
to the
correct one, which throws a SQL Exception - which must be ignored.
Does anyone know why this happens?
Following is the information I'd collected as support. Maybe it'll still
help...
Here's the java app (which works):
____________________________________________________________________________
_______
import java.sql.*;
public class JDBCTest {
public static void main( String args[]){
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con =
DriverManager.getConnection("jdbc:odbc:Crescent", "",
"");
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery("SELECT * FROM DISTRIBUTORS
ORDER BY
STATE");
while (rs.next()) {
String s1 = rs.getString("Company Name");
String s2 = rs.getString("Address 1");
String s3 = rs.getString("State");
System.out.println(s3 + " " + s1 + " " + s2);
}
} catch (Throwable t){
System.out.println(t);
}
}
}
****************************************************************************
*******
...and here's the servlet (which doesn't - see log entry below):
____________________________________________________________________________
_______
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.sql.*;
public class Servlet3 extends HttpServlet {
public static final String TITLE = "JDBC Fetcher";
protected Connection con;
public void init(ServletConfig config) throws ServletException {
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con = DriverManager.getConnection("jdbc:odbc:Crescent", "",
"");
} catch ( Throwable t) {
throw new ServletException("In init(): " + t.toString());
}
}
public void service (HttpServletRequest request, HttpServletResponse
response)
throws ServletException, IOException
{
// set content type and other response header fields first
response.setContentType("text/html");
// get the communication channel with the requesting client
PrintWriter out = response.getWriter();
// get the server identification
String server =
getServletConfig().getServletContext().getServerInfo();
// write the data
out.println("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 3.2//EN\">"
+ "<HTML>"
+ "<HEAD>"
+ " <TITLE>" + TITLE + "</TITLE>"
+ " <META NAME=\"Author\" CONTENT=\"" + server + "\">"
+ "</HEAD>"
+ "<BODY BGCOLOR=\"#FFFFFF\">"
+ " <H1>" + TITLE + "</H1>"
+ " <H2>Congratulations, " + server + " is working!</H2>"
+ " <H3>[ local time is <font color='#FF9900'>"
+ new java.util.Date() + "</font> ]</H3>"
+ " <FONT SIZE=\"-1\">Copyright (c) 1997-99"
+ " <A HREF=\"http://java.apache.org/\">The Java Apache
Project</a><br>"
+ " All rights reserved.</FONT>"
+ " </CENTER>");
out.println("<H1>Distributors<P><TABLE>");
try {
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery("SELECT * FROM
DISTRIBUTORS ORDER BY
STATE");
while (rs.next()) {
String s1 = rs.getString("Company Name");
String s2 = rs.getString("Address 1");
String s3 = rs.getString("State");
System.out.println(s1 + " " + s2);
out.println("<TR><TD>" + s3 + "</TD><TD>" + s1
+ "</TD><TD>" + s2 +
"</TD></TR>");
}
} catch ( Throwable t) {
throw new ServletException("In service(): " +
t.toString());
}
out.println("</TABLE>");
out.println("</BODY>"
+ "</HTML>");
}
}
****************************************************************************
*******
Relevant non-commented lines from jserv.properties:
____________________________________________________________________________
_______
wrapper.path=C:\WINNT\system32;C:\WINNT;D:\infra\jdk1.3\bin;D:\infra\jdk1.3\
jre\bin
wrapper.classpath=.
wrapper.classpath=D:\infra\jdk1.3\jre\lib\rt.jar
wrapper.classpath=D:\infra\JServ1.1\ApacheJServ.jar
wrapper.classpath=D:\infra\jsdk2.0\lib\jsdk.jar
wrapper.classpath=D:\infra\j2sdkee1.2.1\lib\j2ee.jar
wrapper.classpath=D:\infra\j2sdkee1.2.1\lib\ejb10deployment.jar
wrapper.env=windir=C:\WINNT
****************************************************************************
*******
--
--------------------------------------------------------------
Please read the FAQ! <http://java.apache.org/faq/>
To subscribe: [EMAIL PROTECTED]
To unsubscribe: [EMAIL PROTECTED]
Archives and Other: <http://java.apache.org/main/mail.html>
Problems?: [EMAIL PROTECTED]
--
--------------------------------------------------------------
Please read the FAQ! <http://java.apache.org/faq/>
To subscribe: [EMAIL PROTECTED]
To unsubscribe: [EMAIL PROTECTED]
Archives and Other: <http://java.apache.org/main/mail.html>
Problems?: [EMAIL PROTECTED]