<%@ page import="java.sql.*" %>
<%@ page errorPage="HandleError.jsp %>
<%! Connection conn;
Statement stat;
ResultSet res;
String id;
String name;
%>
<%
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
conn = DriverManager.getConnection("jdbc:odbc:cust");
stat = conn.createStatement();
res = stat.executeQuery("Select * from Cutomers");
res.next();
id = res.getString(1);
name = res.getString(2);
}
catch(Exception e) {
System.out.println("error 1"); } %>
<tr>
<td><%= id%></td>
<td><%= name%></td>
</tr>
<% res.close();
stat.close();
conn.close();
%>
The "cust" is an .mdb and I have added its name in the ODBC control panel of
Win NT. I have added two lines in the default.properties file of the j2ee
server from SUN which comes with the pet store sample app (although I don't
think they are required):
jdbc.drivers=sun.jdbc.odbc.JdbcOdbcDriver
jdbc.datasources=jdbc:odbc:cust
And here is the error in the browser:
Error: 500
Internal Servlet Error:
org.apache.jasper.compiler.ParseException: D:\testing\TABLE.jsp(21,44)
Attribute sun.jdbc.odbc.JdbcOdbcDriver has no value
at
org.apache.jasper.compiler.JspReader.parseAttributeValue(JspReader.java:476)
at
org.apache.jasper.compiler.JspReader.parseTagAttributes(JspReader.java:592)
at org.apache.jasper.compiler.Parser$Directive.accept(Parser.java:181)
at org.apache.jasper.compiler.Parser.parse(Parser.java:1056)
at org.apache.jasper.compiler.Parser.parse(Parser.java:1031)
.................
The cust, the server and the browser are all on the same PC. Any help??
'Customers' is spelled wrong. That could be your problem.
Don't worry, I've done this a million times myself :-)
Sender wrote:
> res = stat.executeQuery("Select * from Cutomers");
--
Michael Davis
Damaru
Custom Programming - Web Development - Database Design
http://www.damaru.com
416-540-1284
Missing "
Tom
At least your code is correct. I have run it on my comp, it's
working. I just wanna ask you if the table 'cutomers' exists in you
.MDB ? the spelling is 'cutomers' or 'customer' ?
Cedric
"Tom Davies" <tomd...@optushome.com.au> wrote in message
news:3c22dec6$0$6406$afc3...@news.optusnet.com.au...
>I am learning JSP and JDBC and try to make my first script works. Here is
>the code:
>
><%@ page import="java.sql.*" %>
><%@ page errorPage="HandleError.jsp %>
><%! Connection conn;
> Statement stat;
> ResultSet res;
> String id;
> String name;
>%>
This is not the answer to your original question, but if you don't fix
it, it will trip you up later:
Declare those variables in a scriptlet <% ... %> not a declaration <%!
... %>. Remember that servlets are by default multithreaded, so if
multiple requests are handled simultaneously, any instance variables
can potentially be overwritten.
--
Phil Hanna
Author of JSP: The Complete Reference
http://www.philhanna.com