program created and compilation error of connection rightly created n tested

Ads
 

program created and compilation error of connection rightly created n tested

// I have made connection as the data source dsn2 and i have also created table named Tab1 in SQL server 2008..it is compiled correctly but is giving error for connection on which other programs are running smoothly...:(

import java.awt.*; import java.awt.event.*; import java.awt.FlowLayout; import java.sql.*; import javax.swing.*; public class Bank extends JFrame

implements ActionListener { static JLabel label1,label2,label3,sep; static JButton

sign,create,deposit,withdraw,trans,balance,cl

ose,clear; static JTextField txtA1; static JTextField txtA2; static Connection con; static Statement st1,st2,st3; static ResultSet rs1; int numd; int numf; int nume; public Bank() { super(" Mukunth's Bank"); setLayout(new FlowLayout()); try { Class.forName

("sun.jdbc.odbc.JdbcOdbcDriver"); con =

DriverManager.getConnection

("jdbc:odbc:dsn2");

rs1=st1.executeQuery("select * from tab1"); st1=con.createStatement(); } catch(Exception e) { System.out.println

("there was some error in establishing

connection : "+e); } sep = new JLabel("Existing User

Signin : "); add(sep); label1 = new JLabel(" Account

Number : "); add(label1); txtA1 = new JTextField(15); add(txtA1); label2 = new JLabel(" Name :

  ");
add(label2);
txtA2 = new JTextField(15);
add(txtA2);
sign=new JButton("SIGN IN");
add(sign);
sep = new JLabel("

"); add(sep); sep = new JLabel("

"); add(sep); sep = new JLabel("New User

Signin : "); add(sep); create=new JButton("CREATE

ACCOUNT"); add(create); sep = new JLabel("

"); add(sep); sep = new JLabel("

                          ");
add(sep);
deposit=new JButton

("DEPOSIT"); add(deposit); withdraw=new JButton

("WITHDRAW"); add(withdraw); trans=new JButton

("TRANSACTION"); add(trans); balance=new JButton("BALANCE"); add(balance); clear=new JButton("CLEAR"); add(clear); sep = new JLabel("

"); add(sep); close=new JButton("CLOSE"); add(close); create.addActionListener(this); deposit.addActionListener(this); withdraw.addActionListener(this); trans.addActionListener(this); balance.addActionListener(this); clear.addActionListener(this); close.addActionListener(this); sign.addActionListener(this); deposit.setEnabled(false); withdraw.setEnabled(false); trans.setEnabled(false); balance.setEnabled(false); } public void actionPerformed(ActionEvent

e) { if(e.getSource()==create) { String stra =

JOptionPane.showInputDialog(null,"Please

enter the NAME to open a CURRENT

ACCOUNT"); String strb

= JOptionPane.showInputDialog

(null,"Please enter the ACCOUNT

NUMBER"); if(stra==null ||

strb==null) {

JOptionPane.showMessageDialog(null,"

Either any one or both the values were left

blank"); deposit.setEnabled(false);

withdraw.setEnabled(false);

trans.setEnabled(false);

balance.setEnabled(false);

create.setEnabled(true); sign.setEnabled

(true);
} else { try {

st2=con.createStatement(); String

rr="insert into tab1 values('"+stra

+"','"+strb+"',0,0,0)";

st2.executeUpdate(rr); st2.close();

JOptionPane.showMessageDialog

(null,"ACCOUNT Created Successfully");

txtA1.setText(strb);

txtA2.setText(stra); } catch(Exception e2) {

JOptionPane.showMessageDialog(null,"

There is already a user with same

ACCOUNT NUMBER ,Give another

ACCOUNT NUMBER "); }

deposit.setEnabled(true);

withdraw.setEnabled(true);

trans.setEnabled(true);

balance.setEnabled(true);

create.setEnabled(true); sign.setEnabled

(true); } } else if(e.getSource()==sign) {

String num=txtA1.getText(); try {

st1.close();

st1=con.createStatement();

rs1=st1.executeQuery("Select * from tab1

where AccNum Like '"+num+"'");

rs1.next();

txtA1.setText(rs1.getString("AccNum"));

txtA2.setText(rs1.getString("UserName")); } catch

(Exception e2) {

JOptionPane.showMessageDialog

(null,"Invalid Account Number"); }

deposit.setEnabled(true);

withdraw.setEnabled(true);

trans.setEnabled(true);

balance.setEnabled(true);

create.setEnabled(false); } else if(e.getSource()==deposit) { String strc =

JOptionPane.showInputDialog(null,"Please

enter the amount to be DEPOSITED");

numd=Integer.parseInt(strc); int

numb=Integer.parseInt(txtA1.getText()); if

(numd<=0) {

JOptionPane.showMessageDialog(null," NO

Amount Deposited"); }

else { try { int

num,num1;

st3=con.createStatement();

rs1=st3.executeQuery("select * from tab1

where Accnum like '"+txtA1.getText()+"'"); rs1.next();

num1=Integer.parseInt(rs1.getString

("Deposit"));

num=Integer.parseInt(rs1.getString

("Balance"));

JOptionPane.showMessageDialog

(null,"Amount Deposited Successfully ,

Amount is "+numd); numf=num

+numd;

num1=num1+numd;

st2=con.createStatement();

String ss="update tab1 set

Deposit="+num1+" where

AccNum="+numb+""; String

aa="update tab1 set Balance="+numf+"

where AccNum="+numb+"";

st2.executeUpdate(ss);

st2.executeUpdate(aa);

st2.close();

st3.close(); } catch

(Exception e2) {

JOptionPane.showMessageDialog

(null,"Amount can not be DEPOSITED"); } } } else if(e.getSource()==withdraw) { String strd =

JOptionPane.showInputDialog(null,"Please

enter the amount to be WITHDRAWN"); nume=Integer.parseInt(strd); int numc=Integer.parseInt

(txtA1.getText()); if(numf<=nume) {

JOptionPane.showMessageDialog

(null,"Sorry can not Withdraw, no sufficient

Balance"); } else { try { int num1;

st3=con.createStatement();

rs1=st3.executeQuery("select * from tab1

where Accnum like '"+txtA1.getText()+"'"); rs1.next();

num1=Integer.parseInt(rs1.getString

("Withdraw"));

numf=Integer.parseInt(rs1.getString

("Balance"));

JOptionPane.showMessageDialog

(null,"Amount Withdrawn is "+nume);

numf=numf-nume;

num1=num1+nume;

st2=con.createStatement(); String

pp="update tab1 set Withdraw="+num1+"

where AccNum="+numc+""; String

pp1="update tab1 set Balance="+numf+"

where AccNum="+numc+"";

st2.executeUpdate(pp);

st2.executeUpdate(pp1);

st2.close(); } catch(Exception e2) {

JOptionPane.showMessageDialog(null,"

Can't WITHDRAW "); }
} }

else if(e.getSource()==balance) { String num=txtA1.getText();

        try
        {

st3=con.createStatement();

rs1=st3.executeQuery("select * from tab1

where Accnum like '"+num+"'"); rs1.next();

numf=Integer.parseInt(rs1.getString

("Balance"));

JOptionPane.showMessageDialog

(null,"Balance is "+numf);
} catch(Exception e2) {

JOptionPane.showMessageDialog(null,"

Balance null "); }

 }

else if(e.getSource()==trans) {
String strq =

JOptionPane.showInputDialog(null,"Enter

the ACCOUNT NUMBER to view the

TRANSACTION DONE"); int

numk=Integer.parseInt(strq); int numa=Integer.parseInt

(txtA1.getText()); if

(numk==numa) {

JOptionPane.showMessageDialog

(null,"Amount Deposited is "+numd);

JOptionPane.showMessageDialog

(null,"Amount Withdrawn is "+nume); } else {

JOptionPane.showMessageDialog(null,"The

Account Number is not the same as in the

TEXTFIELD"); } }

else if(e.getSource()==clear) {

txtA1.setText("");

txtA2.setText("");

deposit.setEnabled(false);

withdraw.setEnabled(false);

trans.setEnabled(false);

balance.setEnabled(false);

create.setEnabled(true); sign.setEnabled(true); } else if(e.getSource()==close) { System.exit(0); } } public static void main(String args[]) { Bank obj = new Bank(); obj.setDefaultCloseOperation

(JFrame.EXITONCLOSE); obj.setSize(250,320); obj.setVisible(true);
}

}

View Answers

Ads









Related Tutorials/Questions & Answers:
program created and compilation error of connection rightly created n tested
program created and compilation error of connection rightly created n... error for connection on which other programs are running smoothly...:( import... ("there was some error in establishing connection : "+e); } sep
i have created interface program for simple arithmetic operation but its show some error can i get reason and mistakes
i have created interface program for simple arithmetic operation but its show some error can i get reason and mistakes  import java.io.*; interface arith { int a=5; int b=8; void add(); void mul(); void sub(); void
Advertisements
i have created interface program for simple arithmetic operation but its show some error can i get reason and mistakes
i have created interface program for simple arithmetic operation but its show some error can i get reason and mistakes  import java.io.*; interface arith { int a=5; int b=8; void add(); void mul(); void sub(); void
compilation error
compilation error  Hi my program below is not compiling,when I try to compile it i'm getting the error message "tool completed with exit code 1".The loop has to be at the end of the program can you help me. Blockquoteimport
compilation error - Java Beginners
this program it is giving an error as integer number is too large.why? and what...compilation error  class s { public static void main(String ar[]) { int j=0834
java compilation error - Hibernate
java compilation error  hi, i have made an registration page whosevalues should be inserted into database. i have used hibernate and eclipse it is working fine. but when i make a war file and deploy it using ant and then run
Java compilation error - Java Beginners
Java compilation error  Method overridden problems in compile time error
create table in mysql of split file created in java
create table in mysql of split file created in java  i have created splite file in java. now i want to create table from splited data how to do
java compilation error - Java Beginners
java compilation error  i have downloaded java software(version 6 update 12) from www.java.com. whenever i try to compile the program using javac command, error message is displayed javac is not recognized as an internal
how to validate values in the dynamically created textboxes?
how to validate values in the dynamically created textboxes?  how to validate values in the dynamically created textboxes in HTML using javascript...;script language="javascript"> var n=1; //FUNCTION TO REMOVE TEXT BOX ELEMENT
what is the working of JVM when An object is created of a class?
what is the working of JVM when An object is created of a class?  what is the working of JVM when An object is created of a class?   When the JVM creates the instance of your class object,the object instance is stored
How many objects are created in the code below? Explain.
How many objects are created in the code below? Explain.  Hi, Here is my code public static void main(String[] args) {String s1 = "abc"; StringBuffer s2 = new StringBuffer(s1); StringBuffer s3= s2; StringBuffer s4 = new
how to display the output of the newly created excel file
how to display the output of the newly created excel file  the following program will create the test.xlsx file, how can i display the content of the test.xlsx file in the web browser? thanks, %@ page import
Accessing dynamically created variables inside a function
Accessing dynamically created variables inside a function  Hi, I'm sure this is a stupid question but I've been trying to find the solution for days..._query("INSERT INTO `messages` (message, uid_fk, poster_id,ip,created,uploads) VALUES
jsp directory created in net beans but not able to access
jsp directory created in net beans but not able to access  File f = new File (config.getServletContext().getRealPath("/") + "artists/" +username); f.mkdir(); File video = new File (config.getServletContext().getRealPath
ftp connection error php
ftp connection error php  Getting a ftp connection error in php
connection proxy error in hibernate
connection proxy error in hibernate  while we get connection through hibernate we arise an error connection proxy error while we are using multiple connection's
what is jvm instance, how is it created, how is related to thread?
what is jvm instance, how is it created, how is related to thread?  what is jvm instance, how is it created, how is related to thread
error oracle database connection?
error oracle database connection?  hi now i am trying to connect oracle database and also insert my data into table, but it's not working.. I created...; PreparedStatement stmt=null; Connection con =null; ResultSet rs=null
variables are **called instance variables because they are created** whenever an object of the class is instantiated.
variables are **called instance variables because they are created** whenever... instance variables because they are created whenever an object of the class... variables because they are created whenever an object of the class
error in driver connection
error in driver connection  String driver = "org.gjt.mm.mysql.Driver"; Class.forName(driver).newInstance(); //error at this line Connection con=null; ResultSet rst=null; Statement stmt=null
SQL connection error in android
SQL connection error in android  hi, i am android developer . recently i made one application connect with sql server 2005 using jtds...:sql:Exception : BUFFERDIR connection property invalid. if you have any answer
Error n Exception
Error n Exception  Difference between errors and exceptions
How to read PDF files created from Java thru VB Script
How to read PDF files created from Java thru VB Script  We have created the PDF file thru APache FOP but when we are unable to read the data thru QTP(it's an HP Automation tool). Do u have any addin's to install with QTP
connection proxy error in hibernate
connection proxy error in hibernate  while we get connection through hibernate we arise an error connection proxy error while we are using multiple error message is like below statements SEVERE: Servlet.service() for servlet
connection database error
connection database error  import java.awt.EventQueue; // import...{ Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection...;which type of error occurs? Specify it. Is NWIND is your dsn
Java Compilation error. Hibernate code problem. Struts first example - Hibernate
Java Compilation error. Hibernate code problem. Struts first example  Java Compilation error. Hibernate code problem. Struts first example
problem in inserting data in databases created in netbeans using jsp..
problem in inserting data in databases created in netbeans using jsp.. ... created table inside netbeans through sql editor.and tried to make a login page whose...{ Class.forName("com.mysql.jdbc.Driver"); Connection con
Accessing MS ACCESS databse using a HTML webpage [created using Javascript]
Accessing MS ACCESS databse using a HTML webpage [created using Javascript]  HI team, This is Srinivas, and I have a query and i explained here... I have to save some datas in an MS ACCESS database file [*.mdb], after
dynamically created links id from mysql table is not getting
dynamically created links id from mysql table is not getting  guys, i'm trying to access dynamically called attributes from mysql table as a link to another page, but while i'm trying to access its value, i'm getting only
How to Validate dynamically created text box in HTML using Javascript
How to Validate dynamically created text box in HTML using Javascript  Here is the HTML code to create text boxes dynamically. It works properly.... And also how to validate the text boxes created dynamically. <html>

Ads