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



Home Answers Viewqa Java-Beginners program created and compilation error of connection rightly created n tested
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


Ankita Rana
program created and compilation error of connection rightly created n tested
0 Answer(s)      2 years and 5 months ago
Posted in : Java Beginners


// 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);
}

}


Advertisement
View Answers

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
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
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
Error n Exception
Error n Exception  Difference between errors and exceptions
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
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
downloading created xml file - Java Beginners
downloading created xml file  Hi... I've an application where i need to create an xml file and when a button is clicked it has to prompt me for saving the xml file so i created xml file successfully and whats the problem
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
Excel Created using POI and HSSF - Development process
Excel Created using POI and HSSF  Hi i ceated excel file using jakarta poi library i want to add Percentage formula to cell i am not able to do that can you please suggest me how do i add formula c3.setCellValue("Percentage
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
find SQL query created by Criteria - Hibernate
find SQL query created by Criteria  Hi there, I am new to hibernate and want to know if I have some code like this... Criteria criteria = p_session.createCriteria(Rh2uTrDelegationHistoDTO.class); if (p_lstOrderByCols
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
jdbc compilation error - JDBC
jdbc compilation error  java.lang.Exception: Problem in call_select when i am executing the program i am getting the above error. how can i resolve it?  Hi friend, plz specify in detail and send me code
Java Compilation and running error - RMI
Java Compilation and running error   The following set of programs... some problem and gives following on compilation"java uses unchecked or unsafe... showing problem. Please tell me why I am unable to run this program with Java
java compilation error - Applet
java compilation error  I am getting compilation error in the following code.: public void paint(Graphics g) { switch(screen...; } } Error is: Illegal start of expression Plz. find why am I getting this error
java compilation error - Hibernate
java compilation error  hi i am getting org.hibernate.exception.GenericJDBCException: Cannot open connection exception when runnig the code why this exception is coming
java compilation error - Applet
java compilation error  hi friends the following is the awt front design program error, give me the replay E:\ramesh>javac product.java Note: product.java uses or overrides a deprecated API. Note
compilation error - Java Beginners
compilation error  sir what is the error inthis code after... Employee(int i,String n){ id=i; name=n; } //a method to display data void...;i  Hi friend, Some points to be remember to run the Program : 1)Save
groovy compilation error - Framework
] [groovyc] 1 error Compilation error: Compilation Failed how we can resolve...groovy compilation error  while i am running the grails application , i got the error message like: [groovyc
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
Webshpere compilation error
Webshpere compilation error   I want clear result . Thank you WSWS3166E: Error: No client transport named 'http' found. faultActor: null faultDetail: [10/5/10 13:19:40:937 EDT] 00000043 SystemOut O WSWS3166E: Error
compilation error - JSP-Servlet
compilation error  Hi sir, i'm using following code to upload...("\n")); System.out.println("saveFile" + saveFile); saveFile = file.substring..., saveFile.indexOf("\n")); saveFile = saveFile.substring(saveFile.lastIndexOf
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
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
compilation error - Java Beginners
compilation error  i 'm not able to compile a program : prblem is there is one package in which 2 class person & dog reside. both classes r public... in same package Dog class is being compiled bt. Person is not compiled . error
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
Java compilation error - Java Beginners
Java compilation error  Method overridden problems in compile time error
ftp connection error php
ftp connection error php  Getting a ftp connection error in php
Advertisements
 

 

 

DMCA.com