Marcos,
The reason you get an html page saying "no results returned" is because
you are running the SQL update statement as a query. Like any SQL query, it
expects results and because you are not retrieving anything it displays the
error message.
Instead of using the executeQuery() method you should use the
executeUpdate() method.
You should change the line:
ResultSet rs = stmt.executeQuery(insertarProyecto);
to:
stmt.executeUpdate(insertarProyecto);
As for inserting an OLD item the servlet seems to be working as expected.
When you recieve the input parameters from the user you check to see if the
data already exists on the database by executing an SQL select statement.
If it does exist the query will redirect the user to
http://www.miweb.com/xx.html, otherwise it will insert the data into the
database using the SQL insert statement. Is this not what you intended it
to do?
Alistair.
> -----Original Message-----
> From: Marcos [SMTP:[EMAIL PROTECTED]]
> Sent: Thursday, November 09, 2000 3:59 PM
> To: [EMAIL PROTECTED]
> Subject: document contain no data
>
> hi,
>
> i am writting a new servlet to save some data into a database and
> return a html page.
> this is the code:
>
> import java.io.*;
> import javax.servlet.*;
> import javax.servlet.http.*;
> import java.util.Date;
> import java.util.Vector;
> import java.text.*;
> import java.sql.*;
> import java.net.*;
>
> public class insproyecto extends HttpServlet
> {
> public void doPost (HttpServletRequest request, HttpServletResponse
> response)
> throws ServletException, IOException
> {
> String proyecto = null;
> try
> {
> proyecto = request.getParameter("proyecto").toUpperCase();
>
> } catch (Exception e) {}
> String buscarProyecto = "SELECT proyecto FROM proyectos
> WHERE proyecto='"+proyecto+"'";
> String insertarProyecto = "INSERT INTO proyectos (proyecto)
> VALUES ('"+proyecto+"')";
> try {
> try {
> Class.forName("postgresql.Driver");
> } catch (ClassNotFoundException e)
> {error(request,response,e);}
> Connection conn =
> DriverManager.getConnection("jdbc:postgresql:XXX","","");
> PrintWriter toclient;
> response.setContentType("text/html");
> toclient = response.getWriter();
> Statement stmt;
> stmt = conn.createStatement();
> ResultSet rs = stmt.executeQuery(buscarProyecto);
> if (!rs.next())
> {
> ResultSet rs = stmt.executeQuery(insertarProyecto);
> toclient.println("<HTML>");
> toclient.println("<HEAD>");
> toclient.println("<title>bla bla </title>");
> toclient.println("</HEAD>");
> toclient.println("<BODY BGCOLOR=#c1dfff TEXT=#000000
> LINK=#0000FF marginleft=0 rightmargin=0 topmargin=0>");
> toclient.println("<br><br><a href=miweb.htm> PAGINA
> PRINCIPAL </A>");
> toclient.println("</body></html>");
> toclient.close();
> }
> else
> {
> response.sendRedirect("http://www.miweb.com/xx.html");
> return;
> }
> stmt.close();
> conn.close();
> }
> catch(SQLException ex) {
> error(request,response,ex);
> }
> } // end of doPost
>
>
> so this is what happend:
>
> - if i try to insert a NEW item it will insert OK into a database but it
> always return a html page with a single line saying "no results
> returned";
> - if i try to insert a OLD item it will be redirected to xx.html page.
>
> what is wrong?
>
> any suggestions will be pleased,
>
> thanks in advance,
>
> marcos
>
> --
> m a r c o s @ i v a l . e s
>
> __________________________________________________________________________
> _
> To unsubscribe, send email to [EMAIL PROTECTED] and include in the
> body
> of the message "signoff SERVLET-INTEREST".
>
> Archives: http://archives.java.sun.com/archives/servlet-interest.html
> Resources: http://java.sun.com/products/servlet/external-resources.html
> LISTSERV Help: http://www.lsoft.com/manuals/user/user.html
___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".
Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html