Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Java-Beginners Check Whether Record is already Exists or Not with Database Connectivity

Have Programming Question? Ask it here!
 
 
 


sushant
Check Whether Record is already Exists or Not with Database Connectivity
2 Answer(s)      4 years and 5 months ago
Posted in : Java Beginners


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

Advertisement
View Answers

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


February 28, 2012 at 12:40 PM


thnks soo mutch....



Related Tutorials/Questions & Answers:
Check Whether Record is already Exists or Not with Database Connectivity - Java Beginners
Check Whether Record is already Exists or Not with Database Connectivity  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
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 '
check if a substring exists in a string
check 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 w1.w3
Check the File Exists in PHP Program
Check 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
PHP File Manipulation File existance checking Tutorial, PHP check file exists
File existence checking If you want to check whether a file exists, you should use file exists PHP function. Syntax: file_exists($path), where...=/images/file1.jpg; file_exists($DOCUMENT_ROOT.$TmpName); where $DOCUMENT_ROOT - PHP
database connectivity
database connectivity  how to create database connectivity between HTML and sql server2005
database connectivity
database connectivity  describe java program steps in order to get connectivity to database along with example
Check whether the number is palindrome or not
Check 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
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...; // check that parameter is exist or not while(parameter.hasMoreElements
Database Connectivity
Database 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
database connectivity
database 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 connectivity
database 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 PHP MySQL Connectivity
Check PHP MySQL Connectivity: The first step of any kind of connectivity is to check whether the connectivity has been established or not. To check... you to check whether your PHP web page has been connected with MySQL server
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
java program to check whether a number is pallindrome or not using recursion???????
java program to check whether a number is pallindrome or not using recursion???????  java program to check whether a number is pallindrome or not using recursion
java program to check whether a number is pallindrome or not using recursion???????
java program to check whether a number is pallindrome or not using recursion???????  java program to check whether a number is pallindrome or not using recursion
java program to compare two hashmaps and check whether they are equal or not
java program to compare two hashmaps and check whether they are equal or not  java program to compare two hashmaps and check whether they are equal
java program to check whether a number is pallindrome or not using recursion???????
java program to check whether a number is pallindrome or not using recursion???????  java program to check whether a number is pallindrome or not using recursion
java program to check whether a number is pallindrome or not using recursion???????
java program to check whether a number is pallindrome or not using recursion???????  java program to check whether a number is pallindrome or not using recursion
java program to check whether a number is pallindrome or not using recursion???????
java program to check whether a number is pallindrome or not using recursion???????  java program to check whether a number is pallindrome or not using recursion
java program to check whether a number is pallindrome or not using recursion???????
java program to check whether a number is pallindrome or not using recursion???????  java program to check whether a number is pallindrome or not using recursion
java program to check whether a number is pallindrome or not using recursion???????
java program to check whether a number is pallindrome or not using recursion???????  java program to check whether a number is pallindrome or not using recursion
add record to database - JDBC
add 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 problem
database 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
Program to check whether two given words pronouncing same or not?
Program to check whether two given words pronouncing same or not?  Program to check whether two given words pronouncing same or not? example: raju and rajoo pronouncing same please help me out
Database Connectivity Withe Oracle
Database 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
database connectivity using mysql
database 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
Database connectivity Hibernate mysql connection.
Database connectivity Hibernate mysql connection.  How to do database connectivity in Hibernate using mysql
Access 2007 database connectivity
Access 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
Display error message if data is already inserted in database
Display error message if data is already inserted in database   Display error message if data is already inserted in database Pls help me Thanks
database connectivity - JDBC
database 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
Check whether the sum of alternate digit of a number is palindrome or not.
Check whether the sum of alternate digit of a number is palindrome... are going to check whether the sum of the alternate digit of a number entered... of this number be 2+4+6 i.e 12) and then check whether this sum is palindrome
Check whether highest number is even or odd
Check 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
Oracle Database connectivity probem
Oracle 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
hibernate record not showing in database - Hibernate
hibernate record not showing in database  session =sessionFactory.openSession(); //inserting rocords in Echo Message table...)); //It showing on console Records inserted 21 But not showing in database
C Program with Database Connectivity
C Program with Database Connectivity  How To Connect MySQL Database in C Program with Graphics
database connectivity in java - JDBC
database 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 - JDBC
database 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 Connectivity
About 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 Connectivity
About 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 connectivity
Java 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.
database connectivity using jsp code
database 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
code to establish jdbc database connectivity in jsp
code to establish jdbc database connectivity in jsp  Dear sir, i'm in need of code and procedure to establish jdbc connectivity in jsp
code to establish jdbc database connectivity in jsp
code to establish jdbc database connectivity in jsp  Dear sir, i'm in need of code and procedure to establish jdbc connectivity in jsp
DataBase connectivity in java with Microsoft sql server2000 - JDBC
DataBase connectivity in java with Microsoft sql server2000  How i can achieve database connectivity with Microsoft sql server2000 in my java source code
Help me on database connectivity in J2ME - Java Beginners
Help me on database connectivity in J2ME  i want help in J2ME. i want code for database connection with MySQL. spcl to fecth and insert data from databse. please help me
how to check username & password from database using jsp
how to check username & password from database using jsp  Hello, I.... in my oracle10G database already contain table name admin which has name, password. name is amit and password is ddave. so hw could i check whether the username
Database connectivity with jsp code - JSP-Servlet
Database connectivity with jsp code  I have written a program in java having connectivity with online_exam. Its working properly. Connection has been established and the code in java is showing the output. But the problem
Advertisements
 

 

 

DMCA.com