<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)
{
}
}
}
Hope this helps,
Layton
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
It works now................
Jim Cheng