codetoad.com
  ASP Shopping CartForum & BBS
  - all for $20 from CodeToad Plus!
  
  Home || ASP | ASP.Net | C++/C# | DHTML | HTML | Java | Javascript | Perl | VB | XML || CodeToad Plus! || Forums || RAM 
Search Site:
Search Forums:
  need help creating mysql database for my java code  placidphyll at 08:13 on Saturday, November 28, 2009
 


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

class createSAccount extends JFrame{
JTextField text1,text2,text3,text4,text5,text6,text7,text8,text10;
JLabel label1,label2,label3,label4,label5,label6,label7,label8,label9,label10,label;
JPasswordField text,text9;
JLabel lab1;
JPanel panel,panel1;
JButton b1,b2,b3,b4;
JTabbedPane tp;
createSAccount(){
JTabbedPane tp=new JTabbedPane();
panel=new JPanel(new GridLayout(10,2));
panel1=new JPanel(new GridLayout(3,2));
label1=new JLabel("Name");
text1=new JTextField(10);
label=new JLabel("Password");
text=new JPasswordField(10);
label2=new JLabel("Year of study");
text2=new JTextField(10);
label3=new JLabel("Faculty");
text3=new JTextField(10);
label4=new JLabel("Course");
text4=new JTextField(10);
label5=new JLabel("University");
text5=new JTextField(10);
label6=new JLabel("Phone No");
text6=new JTextField(10);
label7=new JLabel("Email Id");
text7=new JTextField(10);
label8=new JLabel("Address");
text8=new JTextField(10);
label9=new JLabel("Enter Password");
text9=new JPasswordField(10);
label10=new JLabel("Deposit");
text10=new JTextField(10);
b1=new JButton("Add");
b2=new JButton("Reset");
b3=new JButton("Savings");
b4=new JButton("Withdraw");
panel.add(label1);
panel.add(text1);
panel.add(label);
panel.add(text);
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(label6);
panel.add(text6);
panel.add(label7);
panel.add(text7);
panel.add(label8);
panel.add(text8);
panel.add(b1);
panel.add(b2);
panel1.add(label9);
panel1.add(text9);
panel1.add(label10);
panel1.add(text10);
panel1.add(b3);
panel1.add(b4);

b1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae){
String t1=text1.getText();
String t=text.getText();
String t2=text2.getText();
String t3=text3.getText();
String t4=text4.getText();
String t5=text5.getText();
String t6=text6.getText();
String t7=text7.getText();
String t8=text8.getText();

try{
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/register";, "root", "root");
Statement st=con.createStatement();
int i=st.executeUpdate("insert into bankdata(name,pass,year,faculty,course,university,phoneNo,email,address) values('"+t1+"','"+t+"',"+t2+",'"+t3+"','"+t4+"','"+t5+"',"+t6+",'"+t7+"','"+t8+"')");
JOptionPane.showMessageDialog(null,"Thanks for creating an account.");
}
catch(Exception e){}
}
});
b2.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae){
text1.setText("");
text.setText("");
text2.setText("");
text3.setText("");
text4.setText("");
text5.setText("");
text6.setText("");
text7.setText("");
text8.setText("");
}
});
--------------------------------------------------------------------------------

continue..........

b3.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae){
String t9=text9.getText();
String t10=text10.getText();
int savings=Integer.parseInt(t10);
int bal=0;
try{
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/register";, "root", "root");
Statement st=con.createStatement();
ResultSet rs=st.executeQuery("Select balance from bankdata where pass='"+t9+"'");

if(rs.next()){
bal=rs.getInt("balance");
int ts=savings+bal;
Statement st1=con.createStatement();
st1.executeUpdate("update bankdata set balance="+ts+" where pass='"+t9+"'");
JOptionPane.showMessageDialog(null,"Your savings is: "+ts);
}
}

catch(Exception e){}
}
});
b4.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae){
String t9=text9.getText();
int bal=0;
JOptionPane pane = new JOptionPane("Do you want to withdraw");
Object[] options = new String[] { "Yes", "No" };
pane.setOptions(options);
JDialog dialog = pane.createDialog(null, "Dilaog");
dialog.show();
Object obj = pane.getValue();
String st=obj.toString();
if(st.equals("Yes")){
String st1=JOptionPane.showInputDialog(null,"Enter amount to withdraw");
int withdrawl=Integer.parseInt(st1);
try{
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/register";, "root", "root");
Statement stmt=con.createStatement();
ResultSet rs=stmt.executeQuery("Select balance from bankdata where pass='"+t9+"'");

if(rs.next()){
bal=rs.getInt("balance");
int leftSavings=bal-withdrawl;
Statement stat=con.createStatement();
stat.executeUpdate("update bankdata set balance="+leftSavings+" where pass='"+t9+"'");
JOptionPane.showMessageDialog(null," You have withdrawn "+withdrawl+" shillings and your balance is "+leftSavings);
}
}
catch(Exception e){}
}
else{
System.exit(0);
}
}
});
tp.addTab("Create Account",panel);
tp.addTab("Deposit/Withdraw",panel1);
add(tp);
setVisible(true);
pack();
}
public static void main(String[]args){

createSAccount acc=new createSAccount();
}
}

thanks its urgent,thanks,God help u









CodeToad Experts

Can't find the answer?
Our Site experts are answering questions for free in the CodeToad forums








Recent Forum Threads
•  I am trying to run a programme which is using PGPLOT.When I call it from browser I get following error message.
•  Re: open excel file in html page
•  Java Generics, JPA 2, J2EE, JSF 2, GWT, Ajax, Oracle`s Java Strategies, Flex, iPhone, Agile ALM, Grails, Groovy at India’s No.1 Software Developer Conference
•  Trying to make backcolor change after I enter values
•  Re: Difference between two dates including From & To date
•  Disabe onbeforeunload event?
•  Re: MS Access connection in JSP
•  Re: execute linux commands in perl script
•  Re: Server Name or Address could not be resolved?


Recent Articles
ASP GetTempName
Decode and Encode UTF-8
ASP GetFile
ASP FolderExists
ASP FileExists
ASP OpenTextFile
ASP FilesystemObject
ASP CreateFolder
ASP CreateTextFile
Javascript Get Selected Text


© Copyright codetoad.com 2001-2010