Hi folks,
Greetings from Vancouver, Canada. I'm having a problem using jsp (tomcat and Eclipse) to pull int values from an Access database.
In MS-Access db:
My table is Conferences, and the columns are:
"ID" (int)
"CITY" (String)
"AIRPORT" (String)
"SEATS" (int)
My jsp code below connects fine to the MS-Access db. But it is only able to retrieve 2 columns back:
results.getString("CITY") and
results.getString("AIRPORT")
It can't retrieve a 3rd column
Also, I'm not able to use results.getInt("SEATS") or results.getString("SEATS"). It keeps saying no data found.
BTW, Can the resultset pull different datatypes? Can it retrieve a string column and then retrieve integers from another column?
I thought it could handle different datatypes.
My Code is below:
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<html>
<head></head>
<body>
<%@ page import="java.sql.*" %>
<%Connection conn=null;
try{ Class.forName ("sun.jdbc.odbc.JdbcOdbcDriver");
conn = DriverManager.getConnection("jdbc:odbc:Conferences", "", "");}
catch (Exception exc) { out.println(exc.toString() + " "); }
Statement statement = conn.createStatement();
String s = "SELECT * FROM SingleItem";
Statement statement = conn.createStatement();%>
<font size="+2" face="arial"><b>Conference Registration</b></font>
<form action="confirm.jsp" method="post">
<table border=1 bgcolor="tan" width="100%" align="center">
<tr>
<td>Select One</td><td>City</td><td>Tickets Remaining</td></tr>
<tr>
<%
ResultSet results = statement.executeQuery("SELECT * FROM Conferences");
while (results.next()) {
if (results.getInt("SEATS") > 0) {%>
<td><input type="radio" name="show" value="<%= results.getInt("SEATS")%>"></td> //This line works
<% }
else { %>
<td> </td>
<% } %>
<td><%= results.getString("CITY") %></td>
<td><%= results.getString("AIRPORT")%></td>
<td><%= results.getInt("SEATS")%></td> // This line doesn't work, keep getting no data found below.
</tr>
<% } %>
</table>
<p>
<input type="submit" value="Confirm">
</form>
</body>
</html>
The error Code is:
java.sql.SQLException: No data found
sun.jdbc.odbc.JdbcOdbc.standardError(Unknown Source)
sun.jdbc.odbc.JdbcOdbc.SQLGetDataInteger(Unknown Source)
sun.jdbc.odbc.JdbcOdbcResultSet.getDataInteger(Unknown Source)
sun.jdbc.odbc.JdbcOdbcResultSet.getInt(Unknown Source)
sun.jdbc.odbc.JdbcOdbcResultSet.getInt(Unknown Source)
org.apache.jsp.conference_jsp._jspService(conference_jsp.java:70)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:98)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:331)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:329)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
Help! I'm really stuck! I've taken a 1st year college semester in Java so I have some knowledge of Java. Please post your suggestions or your improved code.
Peter
Problem Using JSP with Microsoft Access db
Started by telemachus, Nov 26 2009 05:34 PM
2 replies to this topic
#1
Posted 26 November 2009 - 05:34 PM
|
|
|
#2
Posted 26 November 2009 - 06:26 PM
Well my first impression is to simply look at what is common between the parts that work and different about the one that doesn't. If you notice, the first two that do work are both String fields in the database. The third one, "SEATS", is an int, not a String. Try using results.getInt("SEATS") instead of getString(). That might work out better for you, and to convert it to a string if you need to use java.lang.Integer.parseInt().
If that's not the answer, repost the results of the change and I'll see if I find anything else.
If that's not the answer, repost the results of the change and I'll see if I find anything else.
Wow I changed my sig!
#3
Posted 26 November 2009 - 07:45 PM
I figured it out. Thanks for your help.
I tried calling the same column twice and the resultset wouldn't let me. Resultset can pass through a db column only once.
So, in my MS-Access db, I just created another column with the same values as "SEATS" (int). I now have 2 columns with identical values: "SEATS" (int) and "AVAILABILITY" (int) with the same values and I can use the ResultSet to use the same values twice.
I tried calling the same column twice and the resultset wouldn't let me. Resultset can pass through a db column only once.
So, in my MS-Access db, I just created another column with the same values as "SEATS" (int). I now have 2 columns with identical values: "SEATS" (int) and "AVAILABILITY" (int) with the same values and I can use the ResultSet to use the same values twice.


Sign In
Create Account

Back to top









