Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / First Aid / January 2004

Tip: Looking for answers? Try searching our database.

Using databases in JSP file

Thread view: 
Piotre Ugrumov - 04 Jan 2004 21:52 GMT
I have create a JSP page that take a string from the table Disponibili and
insert the string in the table invio.
When I execute the page IE return an error, but the page JSP do what I want.
How can I avoid the error?
Thanks.

JSP file:
<%@ page import="java.sql.*" %>

<html>
<head>
<title>Sondaggio</title>
</head>
<body>
<font face="verdana" color="#3300ff" size="2">
<%
Connection conn = null;
Connection conn2=null;
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
conn = DriverManager.getConnection("jdbc:odbc:file","","");
conn2 =DriverManager.getConnection("jdbc:odbc:file","","");
String preferenza = new String(request.getParameter("risposta"));
PreparedStatement st = conn.prepareStatement("SELECT ID, Path FROM
Disponibili WHERE ID = ?");
PreparedStatement st2 = conn2.prepareStatement("INSERT INTO invio (percorso)
VALUES (?)");
st.setString(1, preferenza);
ResultSet rs = st.executeQuery();
if (rs.next()){
String provamus= new String(rs.getString("Path"));
st2.setString(1, provamus);
ResultSet pkk = st2.executeQuery();
st2.close();
conn2.close();
String ciao= new String (rs.getString("ID")+" "+provamus);
out.print(ciao);
}
else out.print("nessun record trovato " + preferenza);
st.close();
conn.close();
%>
<br><br>
<a href="risultati.jsp">Visualizza i risultati parziali</a>
</font>
</body>
</html>

HTML page:
<html><head>
<title>Sondaggio</title>
</head>

<body>

<b><big>Domanda:</big></b>
<form action="first.jsp">
<input name="risposta" type="radio" value="1">prova<br>
<input name="risposta" type="radio" value="2">prova<br>
<input name="risposta" type="radio" value="3">prova<br>
<input name="risposta" type="radio" value="4">prova<br>
<input type="submit" value="vota">
</form>
</font>
</body>
</html
Andrew Thompson - 05 Jan 2004 04:26 GMT
| I have create a JSP page that take a string from the table Disponibili and
| insert the string in the table invio.
| When I execute the page IE return an error, but the page JSP do what I want.
| How can I avoid the error?

(shrug) Depends.  It would help if you
said what the error was..

--
Andrew Thompson
* http://www.PhySci.org/ PhySci software suite
* http://www.1point1C.org/ 1.1C - Superluminal!
* http://www.AThompson.info/andrew/ personal site
Piotre Ugrumov - 05 Jan 2004 09:08 GMT
> | I have create a JSP page that take a string from the table
> Disponibili and
[quoted text clipped - 11 lines]
> * http://www.1point1C.org/ 1.1C - Superluminal!
> * http://www.AThompson.info/andrew/ personal site

This is the error:
type Exception report

message

description The server encountered an internal error () that prevented it
from fulfilling this request.

exception

javax.servlet.ServletException: No ResultSet was produced

org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImp
l.java:682)
    org.apache.jsp.first_jsp._jspService(first_jsp.java:88)
    org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:136)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:856)

org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:3
20)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:293)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:240)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:856)

root cause

java.sql.SQLException: No ResultSet was produced

sun.jdbc.odbc.JdbcOdbcPreparedStatement.executeQuery(JdbcOdbcPreparedStateme
nt.java:97)
    org.apache.jsp.first_jsp._jspService(first_jsp.java:65)
    org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:136)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:856)

org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:3
20)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:293)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:240)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:856)

note The full stack trace of the root cause is available in the Tomcat logs.

Thanks.
Oscar Kind - 06 Jan 2004 20:22 GMT
> This is the error:

<snip: javax.servlet.ServletException: No ResultSet was produced>

As Vincent Vega pointed out, you're executing a statement as if it were a
query. The database doesn't care, it works regardless. The JDBC driver
does care: it tries to interpret the result from the database as a
ResultSet because you told it to do so. That fails.

Follow Vincent's advice and it'll work as expected.

Oscar

Signature

No trees were harmed in creating this message.
However, a large number of electrons were terribly inconvenienced.

Vincent Vega - 05 Jan 2004 10:18 GMT
> ResultSet pkk = st2.executeQuery();

The st2 statement is not a query. Call execute() instead.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.