• asiah

    dis doesn’t wok!!!!!!!!!

    • Vlad

      Hey can you tell me what errors are you getting or what part of the code is not functioning the way it is supposed to?

  • Motboy

    Thank you very much. It works perfectly.

  • krishnaveni

    successfully worked for me…thanks a lot…

  • sarkalay

    Thank a lot. perfectly work for me

  • doak

    Nice to hear that guys. :)

  • showket

    thanks…..it works perfectly

    thnks a lot for this beautiful post

  • Subho

    Compiled successfully. . .bt it didn’t run, cause i dnt knw how to create database using ms access. .can u tell me step by step? I am new in java. . . . Any help would be greatly appreciated

  • Vlad

    This program will only work with MySQL databases. If you want to use MS access then you will have to load the respective drivers.

  • Ms. Yuta Lolap

    String query = “SELECT pass FROM info where username=’”+user+”‘”;

    why have u given +user+ i didn’t get that. I am working with where clause first time in jdbc.

  • Vlad

    The value of textfield ‘name’ is stored in the variable ‘user’. We have concatinated this variable with the sql query. So basically at runtime if you enter ‘tom’ in the ‘name’ textfield, the query would be

    SELECT pass FROM info where username=’tom‘

  • Ms. Yuta Lolap

    The program doesn’t enter in to the If loop! My connection is correct!

    check the following code:

    // TODO Auto-generated method stub
    String user = username.getText();
    String strpass = password.getText();

    try {
    Connection con = DriverManager.getConnection(“jdbc:odbc:MyDB”,”system”,”tiger”);
    Statement st = con.createStatement();
    String query = “SELECT password FROM login where username=’”+user+”‘”;
    System.out.println(query);
    ResultSet rs = st.executeQuery(query);

    while(rs.next())
    {
    String dbpass = rs.getString(2);
    if(dbpass.equals(strpass)){
    System.out.println(“inside while”);
    JOptionPane.showMessageDialog(this,”correct”);

    }
    }

    }
    catch (ClassNotFoundException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }
    catch (SQLException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }*/

    }

  • Ms. Yuta Lolap

    doesnt work!!! please help i have a project to do in one week! its not going in the if loop… db connection successful.

    package com.project.jdbc;

    import java.awt.*;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.sql.*;
    import java.util.logging.Level;
    import java.util.logging.Logger;
    import javax.swing.*;

    @SuppressWarnings(“serial”)
    public class jdbc extends JFrame implements ActionListener {

    JTextField username, password;
    JButton login;

    public jdbc()
    {
    setLayout(new FlowLayout());
    username= new JTextField(20);
    password= new JTextField(20);
    login= new JButton(“Login”);

    add(username);
    add(password);
    add(login);

    login.addActionListener(this);

    }

    public static void main(String[] args) {

    jdbc login = new jdbc();
    login.setVisible(true);
    login.setSize(400, 400);
    login.setDefaultCloseOperation(EXIT_ON_CLOSE);

    /* try {
    Class.forName(“sun.jdbc.odbc.JdbcOdbcDriver”);
    Connection con = DriverManager.getConnection(“jdbc:odbc:MyDB”,”system”,”tiger”);

    Statement stmt = con.createStatement();
    ResultSet res = stmt.executeQuery(“select * from pets”);
    System.out.println(“PID \t PNAME \t PTYPE”);
    while(res.next())
    {

    System.out.println(res.getInt(1)+”\t”+res.getString(2)+”\t”+res.getString(3));
    }
    res.close();
    stmt.close();
    con.close();
    } catch (ClassNotFoundException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    } catch (SQLException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }*/

    }

    @Override
    public void actionPerformed(ActionEvent e) {
    // TODO Auto-generated method stub
    String user = username.getText();
    String strpass = password.getText();

    try {
    Connection con = DriverManager.getConnection(“jdbc:odbc:MyDB”,”system”,”tiger”);
    Statement st = con.createStatement();
    String query = “SELECT pass FROM login where username=’”+user+”‘”;
    System.out.println(query);
    ResultSet rs = st.executeQuery(query);

    if(rs.next())
    {

    String dbpass = rs.getString(“password”);
    if(dbpass.equals(strpass)){
    JOptionPane.showMessageDialog(null,”Login Successful!”);
    }
    else
    {
    JOptionPane.showMessageDialog(null,”Login Unsuccessful!”);
    }
    }
    else
    {
    JOptionPane.showMessageDialog(null,”No Record Found”);
    }

    } catch (SQLException ex) {
    System.out.println(e);
    }
    }
    }

    • penglin

      good

      • shahul

        Nice TutoriaL

  • Vlad

    The program seems to be fine, what does this line display in the output screen.
    String query = “SELECT pass FROM login where username=’”+user+”‘”;
    System.out.println(query);

    You can try this,
    String query = “SELECT pass FROM login where username= ”+user+””;

  • kok

    Thank you.. Cleared a lot of my doubts..!!

  • Alvincent

    This is totally working … by the way, i’m using NetBeans 7.1.1 and a WAMPSERER help by MYSQL Workbench….

    the problem by me when trying to attempt to make this login form is the connection between the database and the program itself, but with the help of NetBeans it really solve the problem…

    Thank You Very Much… :)

  • rah

    Create three button on the JSP which are namely Add product, edit product and delete product.
    A div would be rendered on the screen on click of add product and edit product containing all the relevant fields.
    On edit product, the system would render a text box where the user would be asked for the product id and then on tab of it the product details would be retrieved from the database. For delete, the on tab event would prompt for user confirmation and then on confirmation the product would be deleted from the database. You are free to opt for a better UI design than the one mentioned above
    The Add product and edit product would contain the product id and legal address details like Address line1, Address line2, City, State, Post Code and Country.
    On click of submit button in case of add product, edit product and edit product, appropriate user data would be maintained by the system.
    Success message needs to be shown for all the 3 operations which are namely Add product, Edit product and delete product.

    how to strat with m new to java

  • Akshay

    Man..you are lifesaver..:)

  • beena

    how to create a login webpage n link for registration if user not a already a member

    • Vlad

      You could use a session variable to check if the user has logged in or not. Depending on the value of the session variable, you can display/hide the link for registration.

  • Akshay

    Hi
    Sir ,
    I am in 3rd year of IT engg. I am really weak in swing components in java as compare to J2EE and any. Please tell me any way to improve it.
    Please reply

  • shahul

    nice 1