Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa JDBC LOGIN PROBLEM
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


harikrishna
LOGIN PROBLEM
1 Answer(s)      5 years and 11 months ago
Posted in : JDBC



Advertisement
View Answers

February 11, 2009 at 11:42 PM


Harikrishna,<br/>
The data you provided is partly incomplete. I am giving the solution considering you have Oracle in your system. If you have any other DB, check the
Connection and Drivermanager parts.<br/><br/>

The answer contains 2 parts<br/>
1. Registering the user<br/>
- Create a table in the Database to store user details<br/>
- Put some Signup screen and ask user to enter details along with desired user name and password<br/>
- On submit, send the data to a Jsp or servlet (preferable).<br/>
- Do a primary validation, like empty values and special charecters etc, on the data entered.<br/>
- Using JDBC create a connection and store the values in the database<br/><br/>

2. Validating the login<br/>
- After submitting the User ID and Password in the login page, forward the control to a jsp or servlet(preferable).<br/>
- Do a primary validation, like empty values and special charecters etc, on the data entered.<br/>
- Using JDBC create a connection<br/>
- Create a Statement/ PreparedStatement object and send the connection object as parameter.<br/>
- Create a Resultset object<br/>
- Execute the query to retrive the user details for given User ID, and store the values in the Resultset Object<br/>
- Validate the resultset and content and check for the data in the Password column with the password given by the user<br/><br/>

================================================<br/>
Here I am putting some sample code.<br/>
Send user id and password as commanline arguments.<br/>
Create a table "usermaster" in oracle with uid, pwd, username as columns.<br/>
I just wrote this code on flow. I even't compile this code. This is just to give an idea to you.
Hapy Programming ;-)
================================================<br/>
import java.sql.*

public class JDBCSample {

public static void main( String args[]) {

static String userid=?scott?, password = ?tiger?;
String connectionURL = "jdbc:odbc:test";
// Change the connection string according to your db, ip, username and password

Connection dbConnection = null;
Statement statement = null;
ResultSet rs = null;

try {
// Load the Driver class.
Class.forName(?sun.jdbc.odbc.JdbcOdbcDriver?); //Or any other driver

// If you are using any other database then load the right driver here. For example, for PostgreSQL, Class.forName("org.postgresql.Driver");

//Create the connection using the static getConnection method
dbConnection=DriverManager.getConnection(connectionURL,userid,password)

//Create a Statement class to execute the SQL statement
statement = dbConnection.createStatement();

//Execute the SQL statement and get the results in a Resultset
rs = statement.executeQuery("select username from usermaster where uid='"+args[0]+"' and password='"+args[1]+"'");
//To insert data use the following code
// rs = statement.executeUpdate("insert into usermaster set uid='"+args[0]+"' and password='"+args[1]+"', username='" +args[2]+"'");

// Check the ResultSet for values
if(rs.next()) {
// fetch the row data using the getString method
System.out.println("Welcome " + rs.getString("username"));
} else {
System.out.println("Invalid UserID/Password ");
}
}
catch (SQLException sqle) {
sqle.printStackTrace();
}
catch (Exception ex) {
e.printStackTrace();
}
finally {
// Close the connection
try{
dbConnection.close();
rs.close();
}
exception(Exception ex){
ex.printStackTrace();
}
}
}
}


Related Tutorials/Questions & Answers:
struts- login problem - Struts
struts- login problem  Hi all, I am a java developer, I am facing problems with the login application. The application's login page contains fields like username, password and a login button. With this functionality only
LOGIN PROBLEM - JDBC
LOGIN PROBLEM   sir iam harikrishna studying B.Tech Fourth year sir i'm designing one website in that one i have to give facility as login id and passowrd then my problem is how can we write the code for validating the userid
Advertisements
login problem in java bean - Java Beginners
login problem in java bean  login.jsp no longer redirects..., it is displaying login failed and login success correctly. can u help me with the code immediately  Hi friend, Please give in details of problem
problem in swing program for opening two windows with same login credentials
problem in swing program for opening two windows with same login... developed one application using swings that has username,password when i login... windows with same user ..........but i want when i login into the system with same
login
login  How to create login page in jsp
login
login  How to create login page in jsp
login
login  login page display an error showing failure to login even when the correct information is entered
login
login  how to login admin and user with the same fields(name & password) in single login page while the table for admin and user is seprate in database(mysql) please provide me solution
login
login  i want to now how i can write code for form login incolude user and password in Jcreator 4.50   Hello Friend, Visit Here Thanks
login
java.awt.event.*; class Login { JButton SUBMIT; JLabel label1,label2; final JTextField text1,text2; Login() { final JFrame f=new JFrame("Login Form...(); ResultSet rs=st.executeQuery("select * from login where username='"+value1
login
login  how to create login page in jsp   Here is a jsp code that creates the login page and check whether the user is valid or not. 1...;tr><td></td><td><input type="submit" value="Login">
login
login  i am doing the project by using netbeens.. it is easy to use the java swing for design i can drag and drop the buttons and labels etc.. now i want the code for login.. i created design it contains the field of user name
login
login  i am doing the project by using netbeens.. it is easy to use the java swing for design i can drag and drop the buttons and labels etc.. now i want the code for login.. i created design it contains the field of user name
login
login  i am doing the project by using netbeens.. it is easy to use the java swing for design i can drag and drop the buttons and labels etc.. now i want the code for login.. i created design it contains the field of user name
login
login  i am doing the project by using netbeens.. it is easy to use the java swing for design i can drag and drop the buttons and labels etc.. now i want the code for login.. i created design it contains the field of user name
login page
login page  code for login page
login-logout
login-logout  how to do login and logout using session in php
login page
login page  How to login as different user in php
Login page
Login page  how to create Login page in java
LOGIN ERROR
LOGIN ERROR  ERROR SCRIPT: LOGIN FAILED", $_SESSION['login fail']='0',}?> Ty Team
login and logout
login and logout   > > > > hi, > >... home.jsp code i > created a login form and after submitting... page. > > > > The problem is, when i am
Login authentication
Login authentication  i want d code for login authentication from mysql database on the same pc using swings
Login authentication
Login authentication  i want d code for login authentication from mysql database on the same pc using swings
Login Page
Login Page  Can anyone tell me the steps to create a login page in myeclipse 7.0 and validating it with login database in db2 9.7 ??? Please tell me
LOGIN PAGE
LOGIN PAGE  A java program with "login" as title,menus added, and a text field asking for firstname, lastname, and displaying current date and time
login application
login application  how to create login application ?   Hi, Please check the following tutorials: Video tutorial - JSP Login Logout Example Login Authentication using Bean and Servlet In JSP simple code to login user
Login Program
Login Program  Login program in struts to set username & password in session. and this session is available in all screens for authentication..., Please read it at: Login/Logout With Session Accessing Session Object Thanks
Login modification
Login modification  How can I invalidate a user once he goes back to login page without signing out,I have already tried using session but it doesn't work please help
login box
login box  class file for password and conform password and how it connected to database
login page
login page  pls say how to create a login page in jsp and mysql using netbaens   Hi Friend, Please visit the following links: http://roseindia.net/jsf/netbeans/index.shtml http://roseindia.net/jsp/loginbean.shtml
login data
login data  Hiiii Sir I am doing banking project on Asp.net i have... the data after login i want to show particular data for particular user means if i login i wanna see only myn data how shud i do thanxx in advance
Advertisements
 

 

 

DMCA.com