Home Answers Viewqa JDBC jdbc problem

 
 


harmohit
jdbc problem
1 Answer(s)      a year and 9 months ago
Posted in : JDBC

hi my name is mohit...i am making a project in java swings....pls help me how to check that the username and password are correct...the user inputs the username and password and then i want to match the username and password with the already entered username and password in the database...if the entered values match then the user goes to another page and if the entered values are not correct then the program ends...it just like yahoo mail , gmail....i have made this code in netbeans...i have already entered the values in the database....pls help me guys...i am new to java...pls help me learn...

thanks a lot...

1)login page(this is made in swings)

public class loginpage extends javax.swing.JFrame {

String Username= " " , Password =" ";

public loginpage() {
    initComponents();
}

/** This method is called from within the constructor to
 * initialize the form.
 * WARNING: Do NOT modify this code. The content of this method is
 * always regenerated by the Form Editor.
 */
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {

    jLabel1 = new javax.swing.JLabel();
    jTextField1 = new javax.swing.JTextField();
    jLabel2 = new javax.swing.JLabel();
    jPasswordField1 = new javax.swing.JPasswordField();
    jButton1 = new javax.swing.JButton();

    setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

    jLabel1.setText("Username");

    jLabel2.setText("Password");

    jButton1.setText("login");
    jButton1.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            jButton1ActionPerformed(evt);
        }
    });

    javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
    getContentPane().setLayout(layout);
    layout.setHorizontalGroup(
        layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGroup(layout.createSequentialGroup()
            .addGap(108, 108, 108)
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 62, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addComponent(jLabel2))
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 134, Short.MAX_VALUE)
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                .addComponent(jPasswordField1)
                .addComponent(jTextField1, javax.swing.GroupLayout.DEFAULT_SIZE, 181, Short.MAX_VALUE))
            .addGap(121, 121, 121))
        .addGroup(layout.createSequentialGroup()
            .addGap(217, 217, 217)
            .addComponent(jButton1)
            .addContainerGap(334, Short.MAX_VALUE))
    );
    layout.setVerticalGroup(
        layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGroup(layout.createSequentialGroup()
            .addGap(94, 94, 94)
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
            .addGap(103, 103, 103)
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                .addComponent(jLabel2)
                .addComponent(jPasswordField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
            .addGap(78, 78, 78)
            .addComponent(jButton1)
            .addContainerGap(39, Short.MAX_VALUE))
    );

    pack();
}// </editor-fold>

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                         
   Username = jTextField1.getText();
   Password = jPasswordField1.getText();
 loginconnection c1 = new loginconnection();
  //c1.openconnection();
  //msg = c1.querydetails(Userid , Password);



   /* if(Userid.equals("mohit")&&Password.equals("abc"))
       {
      firstpage b=new firstpage();
      b.setVisible(true);
      this.dispose();    
       }
   else
   {
       System.out.println("wrong");
       System.exit(1);
    }*/
}                                        

/**
 * @param args the command line arguments
 */
public static void main(String args[]) {
    java.awt.EventQueue.invokeLater(new Runnable() {

        public void run() {
            new loginpage().setVisible(true);
        }
    });
}
// Variables declaration - do not modify
private javax.swing.JButton jButton1;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JPasswordField jPasswordField1;
private javax.swing.JTextField jTextField1;
// End of variables declaration

}

2)login connection with the database(this is made in java class)

public class loginconnection { public static void main(String[] args) {

   try
   {

Connection con = null; Statement stmt = null; String querydetails = null;

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); con = DriverManager.getConnection("jdbc:odbc:mohit");

      stmt=con.createStatement();
      stmt.executeUpdate("select * from stud1 where Username = 'at'");
   }
  catch(Exception e3)
  {
      System.out.println(e3);              
  }   

}

}

View Answers

August 17, 2011 at 11:52 AM


import javax.swing.*;
import java.sql.*;
import java.awt.*;
import java.awt.event.*;

class LoginDemo extends JFrame{
 JButton SUBMIT;
 JLabel label1,label2;
 final JTextField  text1,text2;
  LoginDemo(){
    setTitle("Login Form");
    setLayout(null);
    label1 = new JLabel();
    label1.setText("Username:");
    text1 = new JTextField(15);

    label2 = new JLabel();
    label2.setText("Password:");
    text2 = new JPasswordField(15);

    SUBMIT=new JButton("SUBMIT");
    label1.setBounds(350,100,100,20);
    text1.setBounds(450,100,200,20);
    label2.setBounds(350,130,100,20);
    text2.setBounds(450,130,200,20);
    SUBMIT.setBounds(450,160,100,20);
    add(label1);
    add(text1);
    add(label2);
    add(text2);
    add(SUBMIT);

   setVisible(true);
   setSize(1024,768);

 SUBMIT.addActionListener(new ActionListener(){
   public void actionPerformed(ActionEvent ae){
    String value1=text1.getText();
    String value2=text2.getText();
    try{
    Class.forName("com.mysql.jdbc.Driver");
           Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/test", "root", "root");
           Statement st=con.createStatement();
           ResultSet rs=st.executeQuery("select * from login where username='"+value1+"' and password='"+value2+"'");
           int count=0;
           while(rs.next()){
               count++;
           }
    if(count>0){
     JOptionPane.showMessageDialog(null,"Welcome "+value1+" !");
       }
    else{
     JOptionPane.showMessageDialog(null,"Error!");
     text1.setText("");
     text2.setText("");
     }
    }
    catch(Exception e){}
}
 });
  }
  public static void main(String arg[]){
  new LoginDemo();
}
}









Related Pages:
jdbc problem
jdbc problem   hi my name is mohit...i am making a project in java swings....pls help me how to check that the username and password are correct..."); con = DriverManager.getConnection("jdbc:odbc:mohit"); stmt
JDBC related Problem - JDBC
JDBC related Problem  Hey plz check out the following code... = "jdbc:odbc:" + ds; try{ Class.forName("sun.jdbc.odbc.JdbcOdbcDriver... connectivity code ...... my problem is... that even after the successful
jdbc and swing problem in netbeans
jdbc and swing problem in netbeans  i reteived the table from database in a jdbc program. next i want to do is place the table as it is in a jpanel.. i am using netbeans IDE can u tel me how to do that one?? urgent
jdbc and swing problem in netbeans
jdbc and swing problem in netbeans  i reteived the table from database in a jdbc program. next i want to do is place the table as it is in a jpanel.. i am using netbeans IDE can u tel me how to do that one?? urgent
problem in jdbc connection
problem in jdbc connection  when i am trying to insert into apache derby databse using java in netbeans an exceprion is thrown at run time like this:- java.lang.ClassNotFoundException: org.apache.derby.jdbc.ClientDriver....what
dsn problem - JDBC
me how to create dsn (jdbc ) at run time . when we will give our project... to remember to create dsn (jdbc): 1.Create an ODBC DSN Using the Windows... the driver To load the JDBC driver by calling the forName() static method
Servlet problem - JDBC
but however. It gives problem sometimes while at others it works perfectly. I m using jdbc-odbc driver. Can anybody help me plzzzz!!!!   Hi Friend
java programming problem - JDBC
java programming problem  Hi, Request you to provide the source code in Java for the following programming problem : upload .csv file data into oracle database. please send the solution to raichallp@yahoo.in
jdbc oracle connectivity problem
jdbc oracle connectivity problem  Hi All, I am trying to connect my swing application to oracle DB . but class.forname is giving error. Please suggest me if there is some different way to connect swing application to oracle
LOGIN PROBLEM - JDBC
LOGIN PROBLEM   sir iam harikrishna studying B.Tech Fourth year sir... and passowrd then my problem is how can we write the code for validating the userid... with JSP AND JDBC can u plz.........send me the code for checking username
JDBC ODBC related problem
JDBC ODBC related problem  i WANT HELP RELATED TO JDBC CONNECTIVITY... con; con = DriverManager.getConnection("jdbc:odbc:Digambar... THE ERROR PART...... THE QUESTION N PROBLEM IS I WANT TO SELECTE PERTICULAR PAPER FROM
java programming problem - JDBC
java programming problem  Hi, Request you to provide a solution ( analysis & design & unit test plan & code & test criteria ) to the following problem to the following mail id : Problem : upload excel file data into oracle
mysql problem - JDBC
= "jdbc:mysql://localhost:3306/test"; Connection con=null; try
Sequence generator problem - JDBC
,but problem is that when i insert a values it will work and inserted the values.this one i am showing in a table ,but problem is a that it is also created a new
mysql problem - JDBC
mysql problem   hai friends i have some problem with image storing in mysql. i.e while i am using image(blob) for insert the image it says out of bound of size error. please provide the logic for storing normal maxi size
jdbc
jdbc  I can't run my jdbc program because it has error in this line: public static void main(String[] args) the error is:illegal static declaration in inner class would you please let me whats the problem? regards
jdbc
define transactions  define transactions   Whenever a connection is created by using the JDBC, then by default it is in auto- commit mode...() method. If there arises any problem while committing then the set
JDBC - JDBC
JDBC  i am goint to work on JDBC and i knew oracle but very poor in java is it possoble to me to do JDBC is it so please give me SOME SAMPLE ILLUSTRATIONS to understand the way to do work in JDBC with syntaxes  Hi
jdbc - JDBC
."); Connection conn = null; String url = "jdbc:mysql://localhost:3306... what problem you faced and explain it in details and read more information on Netbeans and jdbc visit to : http://www.roseindia.net/jdbc/ http
jdbc - JDBC
in JSP to create a table. 2)how desc can be written in JDBC concepts  Hi friend, Code to help in solving the problem : import java.sql.... = null; String url = "jdbc:mysql://localhost:3306/"; String db
jdbc - JDBC
jdbc  jdbc Expert:Ramakrishna Statement st1=con.createStatement... table; " here rs10.getString(1) " is the only primary key solve this problem... Deletion Example"); Connection con = null; String url = "jdbc:mysql://localhost
JDBC - JDBC
JDBC connection to database and show results  Check if the database... problem will get solved...("oracle.jdbc.driver.OracleDriver"); conn = DriverManager.getConnection("jdbc:oracle:thin
jdbc - JDBC
primary key solve this problem.. how to drop and delete values from table... = null; String url = "jdbc:mysql://localhost:3306/"; String dbName.... http://www.roseindia.net/jdbc/ Thanks
jdbc - JDBC
(Exception l) { d.println(l); } } } For any more problem on JDBC...("com.mysql.jdbc.Driver"); Connection con=DriverManager.getConnection("jdbc:mysql://localhost.... but actually i didnt close the resultset object. this is my problem   
JDBC - JDBC
friend, For solving the problem some step to be rememeber : 1.Code to insert
JDBC in JSP - JDBC
JDBC in JSP   Sir, This is the code showing the problem. regards sreejith
JDBC in JSP - JDBC
JDBC in JSP   Sir, This is the code showing the problem. regards sreejith
jdbc compilation error - JDBC
jdbc compilation error  java.lang.Exception: Problem in call_select when i am executing the program i am getting the above error. how can i.... Read for more information. http://www.roseindia.net/jdbc/ Thanks
Jsp,JDBC - JDBC
Jsp,JDBC  Write a Program using Servlet,JSP, JDBC and XML to create a web application for a courier company to provide an online help in tracking the delivery status of items.  Hi friend, For solving the problem
JDBC in JSP - JDBC
JDBC in JSP  Sir, I got a problem in my jsp page which contains a delete query to delete the fields from MySql DB. The delete query is working successfully when we insert the values manuely to the table. When we insert values
Servlet problem
problem from last three month and now i hope rose india developers... specified" I have latest jdbc connector in server lib dir and also i have... connectivity code it works but problem is with servlet page. My servlet code
regarding jdbc - JDBC
code and details having the error to solve the Problem. Thanks  ... = DriverManager.getConnection("jdbc:mysql://localhost:3306/yourdatabase", "your username", "your
jdbc code - JDBC
jdbc code  Dear Sir, i have created one jsp with two fields 1.username 2.password and i have connected to database...; Hi friend, For solving the problem visit to : http
Problem in jsp.
Problem in jsp.  hello friends, I have a problem in jsp.I want to insert data, which is given by user through a html page into a table.And the table..."); Connection con = DriverManager.getConnection("jdbc:mysql://localhost
Problem in jsp.
Problem in jsp.  hello friends, I have a problem in jsp.I want to insert data, which is given by user through a html page into a table.And the table..."); Connection con = DriverManager.getConnection("jdbc:mysql://localhost
Problem in jsp.
Problem in jsp.  hello friends, I have a problem in jsp.I want to insert data, which is given by user through a html page into a table.And the table..."); Connection con = DriverManager.getConnection("jdbc:mysql://localhost
jdbc mysql - JDBC
jdbc mysql  import java.sql.*; public class AllTableName...=DriverManager.getConnection("jdbc:mysql://localhost:3306/ram","root","root... be problem in your mySql, the above code is working fine. first you check
solve this problem
in table please tell me the solution for thid problem import java.io.*; import... = response.getWriter(); String url = "jdbc:mysql://localhost/zulfiqar?user... out = response.getWriter(); String url = "jdbc:mysql://localhost/test?user
about jdbc - JDBC
about jdbc  Hi folks, my previous question was when "i have a table with primary key then when i enter a value which is already there will cause a problem how to solve it." i know to retrieve all the attributes
JDBC connection
JDBC connection  ![alt text][1]I got exception in Connecting to a MySQL Database in Java. The exception is ClassNotFoundException:com.mysql.jdbc.Driver wat is the problem
uploading problem
=DriverManager.getConnection("jdbc:odbc:DNSlib"); Statement st...(); } } } } %> my problem...: firstly.... then problem solved... bt real problem is when i upload files fusing mozilla
connectivity problem
=DriverManager.getConnection("jdbc:oracle:thin:@127.0.0.1:1521:XE","HR","HR
result problem
=DriverManager.getConnection("jdbc:odbc:test","",""); Statement stmt=con.createStatement...=DriverManager.getConnection("jdbc:odbc:student","",""); Statement stmt
jsp problem
jsp problem  problem:::::::: On JSP form ,when i insert data in text field........at that time action is perform and data is retriev from data base... = DriverManager.getConnection("jdbc:mysql://localhost:3306/test", "root", "root
query problem
(); Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/test
problem of confirmation
problem of confirmation  sir, I tried ur code but when i click on cancel it still submits I dont need to pass id as record is already diaplayed... = DriverManager.getConnection("jdbc:mysql://localhost:3306/inventory", "root", "mca

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.