Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Whast's wrong with the jsp code below?

0 views
Skip to first unread message

Jim Cheng

unread,
Jan 23, 2001, 1:44:28 PM1/23/01
to
I am running Apache/Tomcat on Windows2000 Professional, however, the JSP
code below does not work:

<html>
<head>
<title>JSP jokes sample</title>
</head>
<body>
<p>
<%@ page language="java" %>
<%@ page import="java.sql.*" %>

<table border="1" width="400">
<tr>
<td><b>Name</b></td><td><b>Contents</b></td>
</tr>
<%

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

Connection myConn = DriverManager.getConnection("jdbc:odbc:ejokes",
"", "");

Statement stmt = myConn.createStatement();

ResultSet myResultSet = stmt.executeQuery("select * from jokes1");

if(myResultSet != null) {
while(myResultSet.next()) {

String jokeTitle = myResultSet.getString("title");
String jokeContent = myResultSet.getString("contents");

%>
<tr>
<td><%= jokeTitle %></td>
<td><%= jokeContent %></td>
</tr>
<%
}
}

stmt.close();

myConn.close();
%>
</table>
</body>
</html>

Here is the error message:

Error: 500
Location: /jokes/jokes.jsp
Internal Servlet Error:

javax.servlet.ServletException: [Microsoft][ODBC Driver Manager] Data
source name not found and no default driver specified
at
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:459)

..........
...............


Could any one give some advice?
Thanks................

Jim Cheng

However, the java program below works fine on my machine:

import java.sql.*;
import java.lang.*;

public class test1{

public static void main(String args[]){

Connection myConn;

try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}catch(ClassNotFoundException oie){
}
try{

myConn = DriverManager.getConnection("jdbc:odbc:ejokes", "", "");
Statement stmt = myConn.createStatement();

ResultSet myResultSet = stmt.executeQuery("select * from jokes1");

if(myResultSet != null) {
while(myResultSet.next()) {

String jokeTitle = myResultSet.getString("title");
String jokeContent = myResultSet.getString("contents");

System.out.println(jokeTitle + " --- " +jokeContent);

}
}
} catch(Exception moe)
{

}


}

}


Layton Welborn

unread,
Jan 23, 2001, 2:03:25 PM1/23/01
to
Jim,
Is the ODBC DSN a User DSN or a System DSN. It needs to be a System DSN (that way it is
available to the entire system, not just your userid when signed on).

Hope this helps,
Layton

Jim Cheng

unread,
Jan 23, 2001, 4:11:54 PM1/23/01
to
Hi, I change it to System DSN, now it got a different error messgae:

Error: 500
Location: /jokes/jokes.jsp
Internal Servlet Error:

javax.servlet.ServletException: General error
at org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:459)
...............
Root cause:
java.sql.SQLException: General error
at sun.jdbc.odbc.JdbcOdbc.createSQLException(JdbcOdbc.java:6060)
at sun.jdbc.odbc.JdbcOdbc.standardError(JdbcOdbc.java:6188)
...................................


What is wrong with the jsp code?

Thanks!

Jim

Jim Cheng

unread,
Jan 23, 2001, 4:34:15 PM1/23/01
to
Thanks a lot..............

It works now................

Jim Cheng

0 new messages