Thanx for the help....i need some clarifications

        Hi,  this may help.  Assuming that the name and pass are
registered in the
        ODBC registery

        How do u do this....do the name and password get registered with
the SYSTEM/FILE DSN or there is some other way.

        Next, how do u get the registry values....in the code below it
uses HTML INPUT VALUE=default.
        Does that get the value ?

        import javax.servlet.*;
        import javax.servlet.http.*;
        import java.io.*;
        import java.net.*;
        import java.sql.*;
        import java.util.*;
        public class dbconnection extends HttpServlet {
           protected void doGet(HttpServletRequest
req,HttpServletResponse res)
                       throws ServletException, IOException
           {
              res.setContentType("text/html");
              res.setHeader("pragma", "no-cache");
              PrintWriter out = res.getWriter();
              out.print("<html>");
              out.print("<head>");
              out.print("<title>GSBA Database</title>");
              out.print("</head>");
              out.print("<body>");
              out.print("<center><b><font size=+1>DATABASE
Search</b></center>");
              out.print("<hr><FORM METHOD=POST>");
              out.print("<input type=hidden name=test
value=interface>");
              out.println("<center><font size=4><b> Input Name to Search
        :</b></font><font face='Courier New (Hebrew)'> <input
type=textarea
        name=query></center>");
              out.println("<center><input type=submit
value=submit></center>");
              out.println("<pre>");
              out.println("<font size=3><b>Input Database:</b></font>
<input
        type=textarea name=base value=default>");
              out.println("<font size=3><b>Input Field :</b></font>
<input
        type=textarea name=field value=default>");
              out.println("<font size=3><b>Input Name :</b></font>
<input
        type=textarea name=fpass1 value=default>");
              out.println("<font size=3><b>Input Pass :</b></font>
<input
        type=textarea name=fpass2  value=default>");
              out.print("</pre>");
              out.print("</FORM></BODY></HTML>");
              out.close();
             }

            protected void doPost(HttpServletRequest req,
HttpServletResponse res)
                       throws ServletException, IOException
            {
               res.setContentType("text/html");
               // res.setHeader( "pragma", "no-cache");
               int i;
               PrintWriter out = res.getWriter();
               out.print("<HTML><HEAD>TITLE>List
Manager</TITLE></HEAD><BODY>");
               String query = req.getParameter("query");
               String base = req.getParameter("base");
               String field = req.getParameter("field");
               String fpass1 = req.getParameter("fpass1");
               String fpass2 = req.getParameter("fpass2");
               String url   = "jdbc:odbc:"+base;
                try {
                  Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
                  Connection con = DriverManager.getConnection(url,
fpass1,
        fpass2); // DriverManager.getConnection(url, username,
password);
                  Statement stmt = con.createStatement ();
                  query = "%"+query+"%";
                  query=query.replace('*','%');
                  query=query.replace('?','%');
                  query = "select * from "+field+" where "+field+" like
        "+"'"+query+"'";
                  stmt.setMaxRows(500);
                  ResultSet rs = stmt.executeQuery(query);
                  ResultSetMetaData rsmd = rs.getMetaData();
                  int numCols = rsmd.getColumnCount();
                  out.print("<hr>");
                  out.print("<h3>Database Columns and Data</h3>");
                  out.print("<table border=3>");
                  out.print("<tr>");
                  for (i=1; i<=numCols; i++) {
                    out.print("<th>" + rsmd.getColumnLabel(i) +
"</th>");
                  }
                  out.print("</tr>");
                  // for entire data
                  String str;
                  while (rs.next()) {
                    out.print("<tr>");
                   // for one row
                    for (i=1; i<=numCols; i++) {
                      str = rs.getString(i);
                      out.print("<th>"+str+"</th>");
                    }
                    out.print("</tr>");
                   }
                   out.print("</table>");
                  rs.close();
                  stmt.close();
                  con.close();

                } catch (SQLException ex) {
                    out.print("<hr>*** SQLException caught ***<p>");
                    while (ex != null) {
                      out.print("SQLState: " + ex.getSQLState() +
"<br>");
                      out.print("Message:  " + ex.getMessage() +
"<br>");
                      out.print("Vendor:   " + ex.getErrorCode() +
"<br>");
                      ex = ex.getNextException();
                    }
                }
                catch (java.lang.Exception ex) {
                    ex.printStackTrace();
                }
               out.print("<HR><A HREF=\"");
               out.print(req.getRequestURI());
               out.print("\">Return to query page</A></BODY></HTML>");
               out.close();

             }
            public String getServletInfo() {
              return "Applet used for contacting GSBA Faculty Name
database";
            }
         }


        At 17:23 29/04/99 +0530, you wrote:
        >GetConnection() has 3 constructors as:
        >
        >1.      drivermanager.getConnection(String url)
        >2.      drivermanager.getConnection(String url, String usrname,
String
        >pswd)
        >3.      drivermanager.getConnection(String url, Properties
info)
        >
        >I am using the jdbc:odbc bridge to connect to a database in
SqlServer
        >6.5.
        >
        >A system DSN has been created for the purpose.
        >I have been using the constructor no. 2 in which I specify the
usr name
        >and password with the url. i.e. I hardcode the username and
password.
        >
        >I want to avoid this hardcoding.
        >I tried using the constructor no. 1 with the system DSN but I
got the
        >message "login failed"
        >I also tried with FILE DSN but it said "DSN not found and no
driver
        >specified"
        >
        >Can anyone suggest me the way to avoid this hardcoding and if
it is
        >possible to use "FILE" DSN in jdbc.
        >Also elaborate on the usage of constructor nos 1 and 3.
        >
        >Thanking u in advance
        >Geetanjali
        >

>_______________________________________________________________________
____
        >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

___________________________________________________________________________
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