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

Reply via email to