Hi,
I have a servlet in which an ACCESS 97 database is queried and results are returned to the client. But when two people access the servlet simultaneously one of them sees the other clients' results. As u can guess i dont want this to happen.
To avoid this error i added the SingleThreadModel interface but the problem is not solved.
The code can be seen below.
I would also appreciate other comments to improve the code.
Thanks in advance.
Cem Vardar
IE-METU
Ankara/Turkey
 

import java.sql.*;
import java.io.*;
import java.text.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
 
 
 

public class Yad12 extends HttpServlet implements SingleThreadModel {

  String s;
  int n;
  String p;
  boolean found;
    ResourceBundle rb = ResourceBundle.getBundle("LocalStrings");
 
    public void doGet(HttpServletRequest request,
                      HttpServletResponse response)
        throws IOException, ServletException
    {
        response.setContentType("text/html");

        PrintWriter out = response.getWriter();
        out.println("<html>");
        out.println("<body>");
        out.println("<head>");

        out.println("</head>");
        out.println("<body bgcolor=\"white\">");
 
 

        out.println("<h3> YAD Borc Sorgulama Sayfasi </h3>");
        String id = request.getParameter("id");
        //String name = request.getParameter("firstname");
    String password = request.getParameter("password");
        //out.println(id+"<br>");
        if ( (password != null && password != "") && (id != null && id != "")) {
          //out.println("password" + password + "<br>");
     //out.println("id" + id+ "<br>");
     String url = "jdbc:odbc:yaddernek";
         Connection con;
         Statement stmt;
     String createString;
     String query = "SELECT * FROM dernekweb WHERE Uyenumarasi=" + id + " and webid='" + password+ "'";
         try {
             Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
         } catch(java.lang.ClassNotFoundException e) {
             System.err.print("ClassNotFoundException: ");
             System.err.println(e.getMessage());
         }
 
         try {
             con = DriverManager.getConnection(url, "myLogin", "myPassword");
             stmt = con.createStatement();
             //stmt.executeUpdate(createString);
       ResultSet rs = stmt.executeQuery(query);
 
       if (rs.next()) {
       //while (rs.next()) {
        s = rs.getString(2);
        p = rs.getString(3);
        n = rs.getInt(46);
        //out.println("isim from database=" + s+"<br>");
        //out.println("soyad from database=" + p+"<br>");
        //out.println("borc from database=" + n+"<br>");
        found=true;
       } else{
 
        found=false;
 
       }
       rs.close();
       stmt.close();
             con.close();
 
         } catch(SQLException ex) {
             System.err.println("SQLException: " + ex.getMessage());
         }
 
 
     if (found) {
 
      out.println("sayin "+ s + "  " +p+ "<br>");
      out.println("dernegimize "+ n + "TL " + "borclusunuz <br>");
         } else{
       out.println("Uye no ya da sifre hatasi. Lutfen tekrar deneyin.<br>");
     }
 
 
    } else {
            out.println("YAD borc sorgulama sayfasina hos geldiniz<br>");
            out.println("Lutfen uye numaranizi ve sifrenizi giriniz<br>");
        }
 
 
    out.println("<P>");
        out.print("<form action=\"");
        out.print("Yad12\" ");
        out.println("method=POST>");
        //out.println("id");
        //out.println("<input type=text size=2 name=id>");
        out.println("<br>");
        out.println("Uye NO");
        out.println("<input type=text size=10 name=id>");
        out.println("<br>");
 
    out.println("sifre");
        out.println("<input type=text size=10 name=password>");
        out.println("<br>");
 
        out.println("<input type=submit>");
        out.println("</form>");
     out.println("</body>");
        out.println("</html>");
 
  }

    public void doPost(HttpServletRequest request,
                      HttpServletResponse response)
        throws IOException, ServletException
    {
        doGet(request, response);
    }

} ___________________________________________________________________________ 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