Hello Sir I want Program to Check Whether ID is Already exists in the database with Swing Application ,if It is Already Exists then I want To Show
MsgBox else that will Store in Database.
plz Help Me Sir
March 19, 2010 at 12:32 PM
Hi Friend,
Try the following code:
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.sql.*;
class Form extends JFrame
{
JButton SAVE;
JPanel panel;
JLabel label1,label2,label3,label4,label5;
final JTextField text1,text2,text3,text4,text5;
Form()
{
label1 = new JLabel();
label1.setText("UserID:");
text1 = new JTextField(20);
label2 = new JLabel();
label2.setText("First Name:");
text2 = new JTextField(20);
label3 = new JLabel();
label3.setText("Last Name:");
text3 = new JTextField(20);
label4 = new JLabel();
label4.setText("ADDRESS:");
text4 = new JTextField(20);
label5 = new JLabel();
label5.setText("Email:");
text5 = new JTextField(20);
SAVE=new JButton("SAVE");
panel=new JPanel(new GridLayout(6,2));
panel.add(label1);
panel.add(text1);
panel.add(label2);
panel.add(text2);
panel.add(label3);
panel.add(text3);
panel.add(label4);
panel.add(text4);
panel.add(label5);
panel.add(text5);
panel.add(SAVE);
add(panel,BorderLayout.CENTER);
setTitle("FORM");
SAVE.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae){
String value1=text1.getText();
String value2=text2.getText();
String value3=text3.getText();
String value4=text4.getText();
String value5=text5.getText();
Connection con = null;
String url = "jdbc:
mysql://localhost:3306/";;
String db = "test";
String driver = "com.mysql.jdbc.Driver";
String user = "root";
String pass = "root";
try{
Class.forName(driver);
con = DriverManager.getConnection(url+db, user, pass);
Statement st = con.createStatement();
ResultSet rs=st.executeQuery("select id from register where id like '"+'%'+value1+'%'+"'");
if(rs.next()){
JOptionPane.showMessageDialog(null,"Already Exists");
}
else{
int i= st.executeUpdate("Insert into register(id,firstName,lastName,address,email) values('"+value1+"','"+value2+"','"+value3+"','"+value4+"','"+value5+"')");
JOptionPane.showMessageDialog(null,"Data is successfully inserted into the database." );
st.close();
con.close();
}
}
catch(Exception e){
System.out.println(e);
}
}
});
}
}
class FormDemo{
public static void main(String arg[]) {
try
{
Form frame=new Form();
frame.setSize(300,300);
frame.setVisible(true);
}
catch(Exception e)
{}
}
}
For the above code, we have used database table 'register'.
CREATE TABLE `register` (
`id` bigint(20) NOT NULL auto_increment,
`firstname` varchar(40) default NULL,
`lastname` varchar(40) default NULL,
`address` varchar(100) default NULL,
`email` varchar(100) default NULL,
PRIMARY KEY (`id`)
)
Thanks
Related Tutorials/Questions & Answers:
How to check whether database exists?How to
check whether database exists? Hi,
I have to create a
database in mysql. I am able to create that successfully from using JDBC.
But before to creating the
database, i want to
check whether database exists or not?
How can
Advertisements
JSP check email exists or not from the
database whether
entered email-id
exists or not. The given code accepts the email id from the
user and
check whether the given email id
already exists or not. If it is
already exist in
database, then show a message '
protractor check if element exists to
check if element
exists in protractor framework?
Thanks
Hi,
There are methods protractor to
check if element
exists.
You can use the following...protractor
check if element exists Hi,
We are working
check if a substring exists in a stringcheck if a substring
exists in a string Please I jave an arraylist composed as follwoing
[w1, w2, w3, w4, w1.w2.w3, w2.w3.w4, w3.w4, w2.w4, w1.w3, w1.w2]
w2.w4 is a subset of w2.w3.w4 ?how I recognize it
also ADS
database connectivitydatabase connectivity describe java program steps in order to get
connectivity to
database along with example
database connectivitydatabase connectivity how to create
database connectivity between HTML and sql server2005
Check the File Exists in PHP ProgramCheck the File
Exists in PHP Program Hi,
I trying to create a application to find or retrieve the existing files. So, Please help me or suggest any online reference that explain about the file
exists function in PHP?
Thanks
Database ConnectivityDatabase Connectivity I tried to establish
database connection with sqlserver2008 through GlassFish server.
When I set the path of sqljdbc.jar(E:\Glass Fish\glassfish-v2ur1\javadb\lib\sqljdbc.jar) it shows me error
Acess Record from database.Acess
Record from
database. How to access records from
database and how to display it on view page, with the help of hibernate
database connectivitydatabase connectivity i have written class.forName and getconnection in one method which returns connection string object under particular class and in someother class i want to call that for statement object
database connectivitydatabase connectivity i m trying to connect this servlet with
database but i m not able to
Code is ot giving any error and there is no update in
database plsss somebody can help
code is here
package newpackage;
import
Check whether the number is palindrome or notCheck whether the number is palindrome or not
A palindrome is a word,
phrase... direction. Here we are going to
check whether the number entered by the
user is palindrome or not. You can
check it in various ways but the simplest
method
How to check a file exists or not in java.Description:
This example demonstrate how to
check a file exits at a given path or not.
The method isFile() of the File class
check for its existence. As in the file
path we see '\' (backslash) that is used to denote
add record to database - JDBCadd
record to database How to create program in java that can save
record in
database ? Hi friend,
import java.io.*;
import java.sql....);
if(i!=0){
out.println("The
record has been inserted
database connectivity problemdatabase connectivity problem what if client dont have
database with them then what is other way to run successfully our programm
Please visit the following link:
http://www.roseindia.net/jdbc
Check if parameter exists in servlet request Check if parameter
exists in servlet
request... will see how to
check is parameter
exists in servlet request. In this example... = request.getParameterNames();
int count = 0;
//
check that parameter is exist
Database Connectivity Withe OracleDatabase Connectivity Withe Oracle Develop a program to perform the
database driven operation like insert, Delete,
Update and select. To perform the above operations create one table named
Employee.
Field Name Field Type
EmpId
Access 2007 database connectivityAccess 2007
database connectivity i design an application form... source and destination. pls tell me the code of
connectivity with access 2007
database using JComboBox.thanks
database connectivity - JDBCdatabase connectivity can u ppl pls provide me with
database connectivity programs with MSacces
Hi Friend,
If you havn't create your... a user DSN
4. Select Microsoft Access Driver(*.mdb)
5. Select
database name
database connectivity using mysqldatabase connectivity using mysql java file: eg1.java
package eg;
import java.sql.*;
public class eg1
{
public static void main(String arg......... please
check it and tell me what is the problem
Check PHP MySQL ConnectivityCheck PHP MySQL
Connectivity:
The first step of any kind of
connectivity is to
check whether the
connectivity has been established or not. To
check... of code will help you to
check whether your PHP web page has
been connected
Oracle Database connectivity probemOracle
Database connectivity probem hi
Below is the code of oracle
database connectivity, when i compile it, it will show the error: oracle.jdbc.driver.OracleDriver I am using netbeans 6.5 and tomcat 6.0 and jdk 1.6 i have
database connectivity in java - JDBCdatabase connectivity in java import java.io.*;
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.sql.*;
class Project implements ActionListener
{
JFrame f;
JPanel p1,p2,p3;
JTabbedPane
database connectivity - JDBCdatabase connectivity example java code for connecting Mysql
database using java Hi friend,
Code for connecting Mysql
database using...+dbName,userName,password);
System.out.println("Connected to the
database About DataBase ConnectivityAbout
DataBase Connectivity I want a simple code in which is like two tier application
one system have data base and application is running on other system.
Pls inform the way hoe to connect both system
{I want to run
About DataBase ConnectivityAbout
DataBase Connectivity I want a simple code in which is like two tier application
one system have data base and application is running on other system.
Pls inform the way hoe to connect both system
{I want to run
Java database connectivityJava
database connectivity Hi sir
I need a code to create an application where user enter name in text box and that should be stored in
database.
Plz help me out its very urgent.
import java.sql.*;
import java.awt.
Check whether highest number is even or oddCheck whether highest number is even or odd
In this section, you will learn how to
check highest number between the two numbers and then determine
whether it is odd or even. For this, we have taken two integer variables num1 and num2
database connectivity using jsp codedatabase connectivity using jsp code i have two tables employee and adduser
insert into adduser(Emp_Id,Ename,Designation,Password,ReTypePassword)values('6867678po',(select Ename from employee),(select Designation from employee