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

JSP and JDBC

0 views
Skip to first unread message

Sender

unread,
Dec 20, 2001, 10:30:23 PM12/20/01
to
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;
%>
<%
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??

Michael Davis

unread,
Dec 21, 2001, 12:33:31 AM12/21/01
to
Hi,

'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

Tom Davies

unread,
Dec 21, 2001, 2:08:27 AM12/21/01
to

"Sender" <sen...@happy.net> wrote in message
news:3c22...@newsgate.imsbiz.com...

> <%@ page errorPage="HandleError.jsp %>

Missing "

Tom


Cedric

unread,
Dec 21, 2001, 3:24:08 AM12/21/01
to
Hi,

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

Sender

unread,
Dec 21, 2001, 4:53:41 AM12/21/01
to
Thanks. It's the ". Now it works. Thanks again.

"Tom Davies" <tomd...@optushome.com.au> wrote in message
news:3c22dec6$0$6406$afc3...@news.optusnet.com.au...

Phil Hanna

unread,
Dec 22, 2001, 2:19:37 AM12/22/01
to
On Fri, 21 Dec 2001 11:30:23 +0800, "Sender" <sen...@happy.net> wrote:

>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

0 new messages