Hi,
The folowing is the code to conect to DB and send Query to DB. If it got
records acc to ur condition then it means record exists and user + pass is
validated:
//++++++++++++++++++++++++++++++ CODE +++++++++++++++++++++++++++++++++
// Include these files
<%@ page import="java.sql.*,java.util.*,java.io.*,java.lang.*,java.net.*" %>
<%
Connection con = null;
Statement stmt = null;
ResultSet rst12 = null;
String url = "jdbc:odbc:DB_DSN_NAME";
String driver = "sun.jdbc.odbc.JdbcOdbcDriver";
String login = "DB_LoginName";
String password = "DB_LoginPassword";
String str12 = "" ;
String QueryStr = "";
String userid = request.getParameter("PrevForm_userid_FieldName");
String pass = request.getParameter("PrevForm_password_FieldName");
try
{
Class.forName(driver);
con = DriverManager.getConnection(url,login,password) ;
out.print("<br> step1:Connection created <br>");
QueryStr = "SELECT * from User_TBL Where
userid="+userid+"password="+pass;
stmt = con.createStatement();
out.print(" Statement Developed <br>");
rst12 = sstmt.executeQuery(QueryStr);
out.print("....... Drivers loaded and resultset got .........");
if(rst12.next() == false)
{ out.print("user does not exists");
}
}
catch(Exception e)
{
out.print("Drivers not loaded ");
}
%>
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Hamid Hassan
Software Engineer
Visualsoft-inc.com
-----Original Message-----
From: A mailing list about Java Server Pages specification and reference
[mailto:[EMAIL PROTECTED]]On Behalf Of Sello Mathibe
Sent: Friday, February 09, 2001 3:03 PM
To: [EMAIL PROTECTED]
Subject: Querying a Database in JSP.
> Hi. I've created a JSP login page where I've got a Username field and a
> Password field. I've created a table in my Access database, I've also
> created a DSN and can connect to it in my BEAN. Now my problem is that: I
> want to check if the user/client has entered some data on both fields, if
> he submit before he enters some data, I want to through an error message
> or alert in JavaScript. If something is entered on both fields, I want to
> validate that data from the database through the bean.
>
> Can somebody help me cause, I'm trying to create a huge application, but
> I'm stuck at the beginning!
> Thank You
> Oscar
###########################################
This message has been scanned by F-Secure Anti-Virus for Microsoft Exchange.
For more information, connect to http://www.F-Secure.com/
===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff
JSP-INTEREST".
For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST
DIGEST".
Some relevant FAQs on JSP/Servlets can be found at:
http://java.sun.com/products/jsp/faq.html
http://www.esperanto.org.nz/jsp/jspfaq.html
http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets
===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST DIGEST".
Some relevant FAQs on JSP/Servlets can be found at:
http://java.sun.com/products/jsp/faq.html
http://www.esperanto.org.nz/jsp/jspfaq.html
http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets