Results 1 to 4 of 4
  1. #1
    sweet angle is offline Member
    Join Date
    Jul 2008
    Posts
    22
    Rep Power
    0

    Question mySQL login code??

    hi every one...
    i need a code to login with the username and password using java netbeans from mySQL database.When the user enters the username and password in the login page then it will go to the database and search for the usrname and pw.
    i've search for the code but i coul'nt find it.:(
    How to do it?
    thanks in advance

  2. #2
    luckacc is offline Member
    Join Date
    Nov 2008
    Posts
    8
    Rep Power
    0

    Default

    Hi,is this?

    <%@ page language="java" import="java.sql.*" pageEncoding="UTF-8"%>
    <%
    String username=codestring(request.getParameter("username "));
    String password=codestring(request.getParameter("password "));
    Class.forName("com.mysql.jdbc.Driver");
    String url="jdbc:mysql://localhost:3306/book?user=root&password=acc";// JDBC URL
    Connection conn=DriverManager.getConnection(url);
    Statement stmt=conn.createStatement();
    String sql="SELECT * FROM member WHERE username='"+username+"' and password='"+password+"'";
    ResultSet rs=stmt.executeQuery(sql);
    if(rs.next()){
    out.print(rs.getString("username")+" "+rs.getString("password"));
    }
    %>

  3. #3
    t.Donas is offline Member
    Join Date
    Sep 2008
    Posts
    7
    Rep Power
    0

    Default Login

    Hey Sweet Angle, this is the code I used for the problem you facing. This is just part of it and its working correctly for me. Don't mind the .setVisible methods I used, they are just warning messages I used.

    public void tryLogON()
    {
    UserName = txtUserName.getText();
    PassWord = txtPassword.getText();
    String PASSword = null, USERname = null;

    try
    {
    if(UserName.length() == 0)//Checks if the value(s) are entered in the text field
    {
    //Pops up when no value(s) are entered in the text field
    lblPassNotify1.setVisible(false);
    lblPassNotify2.setVisible(false);
    lblUserIncorrect.setVisible(false);
    lblPassIncorrect.setVisible(false);
    lblUserNotify1.setVisible(true);
    lblUserNotify2.setVisible(true);
    txtUserName.requestFocus();
    }
    else if(PassWord.length() == 0)
    {
    lblUserNotify1.setVisible(false);
    lblUserNotify2.setVisible(false);
    lblUserIncorrect.setVisible(false);
    lblPassIncorrect.setVisible(false);
    lblPassNotify1.setVisible(true);
    lblPassNotify2.setVisible(true);
    txtPassword.requestFocus();
    }
    else
    {
    try
    {
    Statement st = conn.createStatement();
    ResultSet rs = st.executeQuery("SELECT Username,Password FROM UserManager WHERE Username = '" + UserName + "' AND Password = '" + PassWord + "'");


    while(rs.next())
    {
    USERname = rs.getString("Username");
    PASSword = rs.getString("Password");
    }
    if(USERname == null || PASSword == null)
    {
    lblUserNotify1.setVisible(false);
    lblUserNotify2.setVisible(false);
    lblPassNotify1.setVisible(false);
    lblPassNotify2.setVisible(false);
    lblUserIncorrect.setVisible(true);
    lblPassIncorrect.setVisible(true);
    txtUserName.requestFocus();
    }
    else
    {
    //myFrame.setVisible(false);//sets the login window invisible
    dispose();
    //Creates Student Management System class object
    Main_StudentManagementSystem oRecords = new Main_StudentManagementSystem();
    }
    }
    catch(SQLException se)
    {
    JOptionPane.showMessageDialog(null,"SQL (search) error " + se.getMessage(),"Error Occured",JOptionPane.ERROR_MESSAGE);
    }
    }
    }
    catch(Exception e)
    {
    JOptionPane.showMessageDialog(null,"Error: " + e.getMessage(),"Error",JOptionPane.ERROR_MESSAGE);
    }
    }

  4. #4
    carbosound1 is offline Member
    Join Date
    Oct 2010
    Posts
    1
    Rep Power
    0

Similar Threads

  1. login.jsp
    By roo7 in forum Enterprise JavaBeans (EJB)
    Replies: 5
    Last Post: 12-02-2008, 04:58 PM
  2. JSP login page
    By banie in forum JavaServer Pages (JSP) and JSTL
    Replies: 1
    Last Post: 09-06-2008, 05:23 AM
  3. Replies: 0
    Last Post: 06-25-2008, 01:41 PM
  4. Login with mysql
    By fernando in forum JavaServer Pages (JSP) and JSTL
    Replies: 1
    Last Post: 08-07-2007, 04:30 PM
  5. Struts and login
    By Peter in forum Web Frameworks
    Replies: 2
    Last Post: 07-04-2007, 04:36 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •