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...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 Tutorials/Questions & Answers:
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 - JDBCJDBC 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
Advertisements
problem in jdbc connectionproblem 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
jdbc and swing problem in netbeansjdbc 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 netbeansjdbc 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
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
LOGIN PROBLEM - JDBCLOGIN
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 problemJDBC 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
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
jdbc oracle connectivity problemjdbc 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
java programming problem - JDBCjava 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
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 - JDBCmysql 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
Problem to get connection from DAO class to JDBCProblem to get connection from DAO class to JDBC package controller;
import java.sql.Connection;
import java.sql.DriverManager;
public class... {
String DRIVER="oracle.jdbc.driver.OracleDriver";
String URL="
jdbc:oracle
jdbcjdbc 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
jdbcdefine 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
JDBCJDBC why we use batch in
jdbc jdbcjdbc display the records using index in
jdbc jdbcjdbc Hai ,
Give a steps for
jdbc connectivity
JDBC - JDBCJDBC 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
JDBCJDBC How to add set of queries in a single query in
JDBC 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
jdbcjdbc please tell me sir.i dont know
JDBC connection and how to create table in database
jdbc jdbc how to write program to save data and retrieve data from the form in Java
jdbcjdbc why do we need to load
jdbc drivers before connecting to database
JDBCJDBC how to set classpath for eclipse, java, where to copy
jdbc connector
JDBCJDBC in class.forname which driver name we are writing for the connection from
jdbc to sqlserver 2008
jdbcjdbc is it possible to use doget & dopost method with
jdbc to call in a servlet programe
JdbcJdbc A java program with
jdbc connectivity with insert,delete,update options for name,regno,mark1,mark2,total
JDBCJDBC can u send me the code of
jdbc how to join two tables that are in relation
JDBC - JDBCJDBC - limitations of jdbc What are the limitations of
JDBC jdbcjdbc define batch updates define batch updates?exp
JDBC... links:
http://www.roseindia.net/
jdbc/
Jdbc-batch-update.shtml
http://www.roseindia.net/tutorial/java/
jdbc/batchupdateresultsetexample.html
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
jdbcjdbc Write a web based student registration application where the
students can register online with their enrollment no. You are
required to use JSP, Servelet and
JDBC JDBCJDBC save a data in the database I need a code to save a data... between java and mysql using
JDBC and saves the data into the database.
import... con = null;
String url = "
jdbc:mysql://localhost:3306/";
String db
JDBCJDBC code to save a data in the database I need a code to save... the connection between java and mysql using
JDBC and saves the data into the database...!");
Connection con = null;
String url = "
jdbc:mysql://localhost:3306/";
String db
jdbchow can we set transaction level through
jdbc api how can we set transaction level through
jdbc api
Use Connection.setTransactionIsolation(int) to set the desired tansaction level, which takes one of the 5 arguments
jdbchow can we call stored procedure using jdbc how can we call stored procedure using
jdbc
Call a Stored Procedure using...();
For more information, visit the following link:
JDBC call Stored Procedure
jdbc - JDBCJava
JDBC application Database Application in Java
JDBC JDBC - JDBCJDBC Select Count Example Need an example of count in
JDBC