import javax.swing.*;
import java.sql.*;
public class BankAccountDatabase{
	public static void main(String[]args){
				Connection conn=null;
		Statement stmt=null;
		ResultSet rs=null,rs1=null;
		String url="jdbc:mysql://localhost/bankaccount";
		String username="roo";
		String password="";
		String query="",query1="";
		String accname,accnum,accpin;
		int PIN,key,menu,AccountNumber;
		String a,b,c,d,f,g,h,i,j,x,y,z;
		double dep,withdraw;
		double balance=0.0;
		
				try{
						Class.forName("com.mysql.jdbc.Driver");
				}catch(java.lang.ClassNotFoundException e){
				System.err.print("ClassNotFoundException: ");
				System.err.println(e.getMessage());
				}
				
			do{
				a=JOptionPane.showInputDialog("MENU\n\n\n1 - Create Account\n2 - Delete Account\n3 - Login\n4 - Exit\nSelect: ");
				menu=Integer.parseInt(a);
				
				switch(menu){
					case 1:
							int ret=0;
						do{
						    accname=JOptionPane.showInputDialog("Creating Account\n\nEnter Account Name: ");
						    accnum=JOptionPane.showInputDialog("Creating Account\n\nEnter Account Number: ");
						    AccountNumber=Integer.parseInt(accnum);
						    accpin=JOptionPane.showInputDialog("Creating Account\n\nEnter PIN: ");
						    //  PIN=Integer.parseInt(accpin);
						    
						    try{
						    			conn=DriverManager.getConnection(url,username,password);
						    			stmt=conn.createStatement();
						    			query="Select*from AccountProfile where AccountNumber='"+AccountNumber+"'";
						    			rs=stmt.executeQuery(query);
						    			if(rs.next()){
						    				String rec=JOptionPane.showInputDialog("Account Already Exist!\n\n1 - return\n2 - exit");
						    				ret=Integer.parseInt(rec);
						    			}else{
						    				
						    				String query2="insert into AccountProfile VALUES('"+accname+"','"+AccountNumber+"','"+accpin+"')";
						    				query1="insert into AccountBalance VALUES('"+AccountNumber+"','0.0')";
						    				stmt.executeUpdate(query2);
						    				stmt.executeUpdate(query1);
						    				JOptionPane.showMessageDialog(null,"Account Successfully Created!");
						    			}
						    			stmt.close();
						    			
						    						conn.close();
						    						
						         }catch(SQLException ex){
						    	JOptionPane.showMessageDialog(null,"SQLException: "+ex.getMessage()+"\nSQLState: "+ex.getSQLState()+ "\nVendorError: "+ ex/getErrorCode());
						    }
						}while(ret==1);
						
							break;
								
								case 2:
											int ret1=0;
											do{
													accnum=JOptionPane.showInputDialog("Delete Account\n\nEnter Account Number to be Deleted: ");
													AccountNumber=Integer.parseInt(accnum);
													try{
														 conn=DriverManager.getConnection(url,username,password);
														 stmt=conn.createStatement();
														 query="Select*from AccountProfile where AccountNumber='"+AccountNumber+"'";
														 rs=stmt.executeQuery(query);
														 if(rs.next()){
														 	String q="Delete from AccountProfile where AccountNumber='"+AccountNumber+"'";
														 	String q1="Delete from AccountBalance where AccountNumber='"+AccountNumber+"'";
														 	stmt.executeUpdate(q);
														 	stmt.executeUpdate(q1);
														 	JOptionPane.showMessageDialog(null,"Account Successfully Deleted!");
														 	
														 }else{
														 	String rec1=JOptionPane.showInputDialog("No Record Found!\n\n1 - return\n2 - exit");
														 	ret1=Integer.parseInt(rec1);
														 }
														 stmt.close();
														 conn.close();
														
													}catch(SQLException ex){
														JOptionPane.showMessageDialog(null,"SQLException: "+ex.getMessage()+"\nSQLState: "+ex.getSQLState()+"\nVendorError: "+ex.getErrorCode());
													
													}while(ret1==1);
															break;
														case 3:
															int ret2=0;
															int cnt=1;
															do{
																accpin=JOptionPane.showInputDialog("LOGIN\nEnter PIN: ");
																try {
																		conn=DriverManager.getConnection(url,username,password);
																		stmt=conn.createStatement();
																		query="Select*from AccountProfile where PIN='"+accpin+"'";
																		rs=stmt.executeQuery(query);
																		if(rs.next()){
																			String aname=rs.getString(1);
																			String ac=rs.getString(2);
																			int ret3=0;
																			do{
																					a=JOptionPane.showInputDialog("What do you want to do?\n\n1 - Deposit\n2 - Withdraw\n3 - Bal Inquiry\n4 - Cancel");
																					int sel=Integer.parseInt(a);
																					switch(sel){
																						case 1:
																								do{
																									b=JOptionPane.showInputDialog("Deposite\n\nEnter Amount of Money You want to Deposite: ");
																									
																									dep=Double.parseDouble(b);
																																				}while(dep<0);
																											String que="Select*from AccountBalance where AccountNumber='"+ac+"'";
																											rs1=stmt.executeQuery(que);
																											
																											while(rs1.next()){
																												
																												balance=rs1.getDouble(2);
																												
																											}
																											
																											balance=balance+dep;
																											
																											String q2="Update AccountBalance set Balance ='"+balance+"'where AccountNumber='"+ac+"'";
																											stmt.executeUpdate(q2);
																											
																											JOptionPane.showMessageDialog(null,"Ammount Successfully Deposited!");
																											break;
																						case 2:
																								do{
																									c=JOptionPane.showInputDialog("Withdraw\n\nEnter Amount of Money You want to Withdraw: ");
																									withdraw=Double.parseDouble(c);
																								}while(withdraw<0);
																								String q3="Select*from AccountBalance where AccountNumber='"+ac+"'";
																								
																								
																								rs=stmt.executeQuery(q3);
																								while(rs.next()){
																									balance=rs.getDouble(2);
																								}
																								balance=balance-withdraw;
																								if(balance<0){
																									
																									JOptionPane.showMessageDialog(null,"Sorry! Insufficient Balance!");
																								}else{
																									
																									String q4="Update AccountBalance set Balance='"+balance+"'where AccountNumber='"+ac+"'";
																									
																									stmt.executeUpdate(q4);
																									
																									JOptionPane.showMessageDialog(null,"AccountName: "+aname+"\nAccount Number: "+ac+"\nWithdraw: "+withdraw+"\nBalance: "+balance);
																								}
																								
																									break;
																								
																									
																						case 3:
																						         	String q6="Select*from AccountBalance where Accountnumber='"+ac+"'";
																						         	rs=stmt.executeQuery(q6);
																						        	while(rs.next()){
																								             double n=rs.getDouble(2);
																								
																								JOptionPane.showMessageDialog(null,"Account Name: "+aname+"\nAccount Number: "+ac+"\nBalance: "+n);
																							}
																							break;
																							
																				   	case 4:
																								
									   JOptionPane.showMessageDialog(null,"Transaction Cancelled!");
																								break;
																								
																								default:																							
																									JOptionPane.showMessageDialog(null,"Invalid Selection!");	
																					}
																					x=JOptionPane.showInputDialog("Do You want another transaction?\n1 - yes\nany key - no");
																					ret3=Integer.parseInt(x);
																					
																				}while(ret3==1);
																			
																			
																		}else{
																			
																			
																			String rec2=JOptionPane.showInputDialog("PIN Error! "+cnt+" Try(s) Made..\n\n1 - return\n2 - exit");
																			ret2=Integer.parseInt(rec2);
																			cnt=cnt+1;
																			if(cnt==3)break;
																		}
																		stmt.close();
																		conn.close();
																		
																}catch(SQLException ex){
																		JOptionPane.showMessageDialog(null,"SQLException: "+ex.getMessage()+"\nSQLState: "+ex.getSQLState()+"\nVendorError: "+ex.getErrorCode());
																																																}
																
																	}while(ret2==1);
															
																	break;
															
															case 4:
																
																	JOptionPane.showMessageDialog(null,"Goodbye! See You Later..");
																	
																	break;
																	default: JOptionPane.showMessageDialog(null,"Invalid Selection!");
															} 
															z={JOptionPane;showInputDialog("Use this program again? press <1>...");
															key=Integer.parseInt(z);
												}while(key==1);
															}
												}

I need help pls. I already fixed some errors.
I used JCreator v.4 pro on this one..
The errors left are the ones I dont understand and I cant fix.
please help.. I really need to get this program ASAP.

Its an exam project for our finals.
If I cant get it to work by the next 8 hours
I'll fail the exam. T_T

here is the errors found on the codes:
[img]http://i40.tinypic.com/23llc1t.jpg[/img]

or you can download the java file.

You are missing closing bracket on case 2 (just as you close catch block). After that you should be able to continue solve the rest.

case 2:
                    int ret1 = 0;
                    do {
                        accnum = JOptionPane.showInputDialog("Delete Account\n\nEnter Account Number to be Deleted: ");
                        AccountNumber = Integer.parseInt(accnum);
                        try {
                            conn = DriverManager.getConnection(url, username, password);
                            stmt = conn.createStatement();
                            query = "Select*from AccountProfile where AccountNumber='" + AccountNumber + "'";
                            rs = stmt.executeQuery(query);
                            if (rs.next()) {
                                String q = "Delete from AccountProfile where AccountNumber='" + AccountNumber + "'";
                                String q1 = "Delete from AccountBalance where AccountNumber='" + AccountNumber + "'";
                                stmt.executeUpdate(q);
                                stmt.executeUpdate(q1);
                                JOptionPane.showMessageDialog(null, "Account Successfully Deleted!");

                            } else {
                                String rec1 = JOptionPane.showInputDialog("No Record Found!\n\n1 - return\n2 - exit");
                                ret1 = Integer.parseInt(rec1);
                            }
                            stmt.close();
                            conn.close();

                        } catch (SQLException ex) {
                            JOptionPane.showMessageDialog(null, "SQLException: " + ex.getMessage() + "\nSQLState: " + ex.getSQLState() + "\nVendorError: " + ex.getErrorCode());

                        }
                    }//missing closing bracket
                    while (ret1 == 1);
                    break;
commented: Thanks for saving my Grades! +0

Woah! That totally fixed many of the errors. O.o I rechecked it for many times and I didnt saw that.. Thanks! Thank you sooo much!

wondering_ed, I think you may have just found this out yourself, but basically any time you see " ____ expected " it usually means you forgot a closing bracket } or a closing ) somewhere.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.