abt java project

abt java project

this program compile sucessfully but data is not store in data base if any thing correction plz do it

import java.awt.*;
import javax.swing.*;
import java.sql.*;
import java.awt.event.*;
public class simple extends JFrame implements ActionListener{

private static final long serialVersionUID = 1L;
JLabel label1,label2,label3;
JTextField textfield1,textfield2;
JPasswordField pass;
JButton button1,button2;
JPanel panel;
public simple()
{
label1=new JLabel("user Name");
textfield1=new JTextField(15);
label2=new JLabel("Password");
pass=new JPasswordField(15);
label3=new JLabel("address");

textfield2=new JTextField(15);

button1=new JButton("SAVE");
button2=new JButton("cancel");
panel=new JPanel(new GridLayout(15,2));
panel.add(label1);
panel.add(textfield1);
panel.add(label2);
panel.add(pass);
panel.add(label3);

panel.add(textfield2);

panel.add(button1);
panel.add(button2);
button1.addActionListener(this);
button1.setActionCommand("SAVE");

//button1.addActionListener(new ActionListener());
add(panel);
setSize(300,400);
setVisible(true);


}

public void actionPerformed(ActionEvent ae) {
String cmd=ae.getActionCommand();
if (cmd.equalsIgnoreCase("SAVE")){


String value1=textfield1.getText();
String value2=textfield2.getText();
String value3=pass.getText();

Connection con=null;
Statement stm=null;
String user1="";
try
{
Class.forName("org.postgresql.Driver");
con = DriverManager.getConnection("jdbc:postgresql://localhost" + "/smp", "postgres", "postgres");
stm=con.createStatement();
ResultSet res=stm.executeQuery("select *from register where username="+value1+"");
System.out.print("query executed");
if(res.next())
{
user1=res.getString("username");
JOptionPane.showMessageDialog(null,"invalid userName");
}
else
{
stm.execute("insert into register values('" +value1+ "','" +value2+ "','"+value3+"')");
JOptionPane.showMessageDialog(null, "Data successfully saved");

}
}
catch(Exception e)
{

}




}
}
public static void main(String arg[])
{
simple smp=new simple();
}

}
View Answers

February 15, 2010 at 1:42 PM

Hi Friend,

Try the following code:

import java.awt.*;
import javax.swing.*;
import java.sql.*;
import java.awt.event.*;
public class simple extends JFrame implements ActionListener{

JLabel label1,label2,label3;
JTextField textfield1,textfield2;
JPasswordField pass;
JButton button1,button2;
JPanel panel;
public simple(){
label1=new JLabel("user Name");
textfield1=new JTextField(15);
label2=new JLabel("Password");
pass=new JPasswordField(15);
label3=new JLabel("address");
textfield2=new JTextField(15);
button1=new JButton("SAVE");
button2=new JButton("cancel");
panel=new JPanel(new GridLayout(15,2));
panel.add(label1);
panel.add(textfield1);
panel.add(label2);
panel.add(pass);
panel.add(label3);
panel.add(textfield2);
panel.add(button1);
panel.add(button2);
button1.addActionListener(this);
button1.setActionCommand("SAVE");

add(panel);
setSize(300,400);
setVisible(true);
}
public void actionPerformed(ActionEvent ae) {
String cmd=ae.getActionCommand();
if (cmd.equalsIgnoreCase("SAVE")){
String value1=textfield1.getText();
String value2=textfield2.getText();
String value3=pass.getText();

System.out.println(value1+" "+value2+" "+value3);
Connection con=null;
Statement stm=null;
String user1="";
try{
Class.forName("com.mysql.jdbc.Driver");
con = DriverManager.getConnection("jdbc:mysql://localhost:3306/test";, "root", "root");
stm=con.createStatement();
int i=stm.executeUpdate("insert into login(username,password,address) values('"+value1+"','"+value3+ "','"+value2+"')");
JOptionPane.showMessageDialog(null, "Data successfully saved");
}
catch(Exception e)
{
}
}
}
public static void main(String arg[])
{
simple smp=new simple();
}

}

Thanks









Related Tutorials/Questions & Answers:
abt java project - Java Beginners
abt java project  if we want to create a pannel on the button how to write on the code in side the button plz help
abt java project - Java Beginners
abt java project  I don't know too much about java , and I am working on java project, where editor is eclipse and backend postgresql How can i take help about my project, which book I should refers plz help me
Advertisements
abt java project - Java Beginners
abt java project  How to make the home page that contain four tabbedPane like additem, deleteitem ,update etc, so plz help me thanx  Hi.../java/example/java/swing/add_edit_and_delete_employee_inf.shtml If you want
abt java project - Java Beginners
abt java project  this program compile sucessfully but data is not store in data base if any thing correction plz do it import java.awt.*; import javax.swing.*; import java.sql.*; import java.awt.event.*; public class
abt proj - Java Beginners
abt proj  which topic i have to study carefully ,when I am going to start java project using swings  Hi Friend, Learn awt, swing... http://www.roseindia.net/java/example/java/awt/ http://www.roseindia.net
abt proj - Java Beginners
abt proj  if we have already make login page and resister page, if i click on the login button we go to the home page ,home page contain some data plz help
abt java - Java Beginners
abt java   hiiiii i m new to this language i have some problem with my java code ... i working on netbeans .. i write a code for user authetication ... in this code it take user name password and a user certificate(which
abt proj - Java Beginners
abt proj  I made login page, when i click on login button , thaen how to go on home page on home page containe some tab like add, delete, update,etc... the following link: http://www.roseindia.net/java/example/java/swing/add_edit_and_delete
absolutely no idea abt a program - Java Beginners
absolutely no idea abt a program  write a program in java/blue...(" "); System.out.print(arr[j]); } } } For more information on java visit to : http://www.roseindia.net/java Thanks
abt jmeter - Java Server Faces Questions
abt jmeter  how to use jmeter for testing the program?   Hi friend, For using jmeter for testing visit to : http://www.roseindia.net/jmeter/ http://www.roseindia.net/jmeter/using-jmeter.shtml Thanks
ModuleNotFoundError: No module named 'abt'
ModuleNotFoundError: No module named 'abt'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'abt' How to remove the ModuleNotFoundError: No module named 'abt' error
Maven Dependency abt-core_2.11 >> 0.0.2
You should include the dependency code given in this page to add Maven Dependency of com.slamdata >> abt-core_2.11 version0.0.2 in your project
Maven Dependency abt-core_2.11 >> 0.0.3
You should include the dependency code given in this page to add Maven Dependency of com.slamdata >> abt-core_2.11 version0.0.3 in your project
Maven Dependency abt-core_2.12 >> 0.0.2
You should include the dependency code given in this page to add Maven Dependency of com.slamdata >> abt-core_2.12 version0.0.2 in your project
Maven Dependency abt-core_2.12 >> 0.0.3
You should include the dependency code given in this page to add Maven Dependency of com.slamdata >> abt-core_2.12 version0.0.3 in your project
abt the bank application
abt the bank application  pls can u send to me the user table and transaction table sql statement with their datatype used in this bank application to my email
Version of com.slamdata>abt-core_2.11 dependency
List of Version of com.slamdata>abt-core_2.11 dependency
Version of com.slamdata>abt-core_2.12 dependency
List of Version of com.slamdata>abt-core_2.12 dependency
need to ans abt db - JSP-Servlet
need to ans abt db  helllo can you tell me m just starting to knowing abt servlet and i trying to making e-mail site so can you tell me with the java servlet wht is the backhand database to use to proper with that site
Maven Repository/Dependency: com.slamdata | abt-core_2.12
Maven Repository/Dependency of Group ID com.slamdata and Artifact ID abt-core_2.12. Latest version of com.slamdata:abt-core_2.12 dependencies... Maven Web Application in Eclipse? Maven 3 Tutorial Convert Maven project
Maven Repository/Dependency: com.slamdata | abt-core_2.11
Maven Repository/Dependency of Group ID com.slamdata and Artifact ID abt-core_2.11. Latest version of com.slamdata:abt-core_2.11 dependencies... in Eclipse? Maven 3 Tutorial Convert Maven project to Eclipse Web Project
Java Project
Java Project  Java project using with collection and generic with observer design pattern
java project
java project  how many tables are required in backend for online examination system project in jsp If backend is SQL
java project
java project  i would like to get an idea of how to do a project by doing a project(hospital management) in java.so could you please provide me with tips,UML,source code,or links of already completed project with documentation
JAVA project
JAVA project  How to extract tags and their corresponding properties of a "cascading style sheet" file using JAVA
java project
java project  Connecting to MySQL database and retrieving and displaying data in JSP page by using netbeans
Java Project
Java Project  how to write a program for competitive exams(for student practice purpose)? for example: first student have to login after login then he has to select the particular exam what he want to write i.e the exam may
java project - Java Beginners
java project  how can i download the source code for the project college admission system
Java Project - Java Beginners
Java Project  Hello Sir I want Mini Student Admission System project in java with Source Code and Back end Database is MS Access. plz Give That Sir its Very Very Urgent
Java Project - Java Beginners
Java Project  Dear Sir, Right now i am working in java image processing project. In that i have to split in one image like Texture, color..., Please visit the following links: http://www.roseindia.net/java/example
Java Project - Java Beginners
Java Project  Hey, thanks for everything your doing to make us better. Am trying to work on a project in java am in my first year doing software Engineering and the project is m end of year project. Am really believing
Java Project - Java Beginners
Java Project  I'm a III yr Engineering student. I've been ask 2 prepare a project on Java. Can u plz suggest me some topics ?   Hi friend... Java project topic with more information. 1. Asset Management 2. Shopping
java project - Java Beginners
java project  project for internet banking  Hi friend, I am sending you a link. This link will help you. Please visit for more information. http://www.roseindia.net/jsp/bank.shtml Thanks
project - Java Beginners
project in Java  Need example project in Java
JAVA PROJECT - Java Beginners
JAVA PROJECT  Dear Sir, I going to do project in java " IT in HR, recruitment, Leave management, Appriasal, Payroll" Kindly guide me about... etc. I am doing project first time. waiting for your reply, Prashant
java project - Java Beginners
java project  hi this amol i wish to do a project on banking software in java can u help   how can i help u .. and what the kind... adam certified java programmer certified websphere   ya sure!! what
java project - Java Beginners
java project  Can u pls suggest me any ideas for my B.E project? It's urgent... Front end---Java Back end----Oracle IDE---------Netbeans5.5 It should not be completely database oriented... I am not allowed to develop any
Java Project - Java Beginners
Java Project   Write a Java program to create simple Calculator for 4 basic Math operations, Addition, Subtraction, Multiplication and Division... the following link: http://www.roseindia.net/java/example/java/swing/calculator
Java Project - Java Beginners
Java Project  Dear Sir, I have to do Project in "IT in HR i.e. Recruitment, Leave Management, Appraisal & payroll. These are Four main modules... employee master. Now, can you tell in Java programming with Mysql How can
java project - Java Beginners
java project  HAVE START A J2ME PROJECT WITH NO CLEAR IDEA .. ANY ONE... project titled, as ?M-News Application? is basically a mobile news application Project. In our project we are going to develop a Mobile Application which
JAVA Project - Java Beginners
JAVA Project  Hi Friends, Can somebody please tell me a website from where I can download java live projects along with the source code
java project - Java Beginners
java project  Sir, how can i download the source for for the proect college admission system
Java Project - Java Beginners
question in my java project. But this program is shoing error on the 50th line...Java Project  Create a class Computer that stores information about...; public Computer(String n,int s,int sp,String m,double p,int q){ name=n; size=s
JAVA AWT BASE PROJECT
JAVA AWT BASE PROJECT  suggest meaningful java AWT-base project
project detail - Java Beginners
project detail  Dear roseindia, i wnat to the idea for doing project in the java
project detail - Java Beginners
project detail  How to do project in java I am doing final MCA i want to do project I am willing to do project in java or j2ee. But I have no idea so I want some idea about project in java please give some sample project
Project - Java Beginners
Project  Give me a sample project idea done using code Java
Project - Java Beginners
Project  Give me a sample project idea done using code Java
java project - JavaMail
java project  i want to make a project in java on ethernet mailing system.....can you provide the source code of this?and give me more suggestions to make
java project question
java project question  how to calculate bill extracting quantity n price from one database table and inserting the result into another in java   Hi Friend, Visit Here Thanks

Ads