forked from mishrkavita/Online-Banking-System-using-Java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAccount.java
More file actions
139 lines (131 loc) · 4.8 KB
/
Account.java
File metadata and controls
139 lines (131 loc) · 4.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
/******************************************************************************
* Program Author: Kavita Mishra for CSCI 6810 Java and the Internet *
* Date: September, 2018 *
*******************************************************************************/
package com.mishra;
import java.lang.*; //including Java packages used by this program
import java.sql.*;
import com.mishra.*;
public class Account
{
private String Username, Password, Password1, Name;
public Account(String UN, String PassW, String PassW1, String NM) {
Username = UN;
Password = PassW;
Password1 = PassW1;
Name = NM;
}
public Account(String UN, String PassW) {
Username = UN;
Password = PassW;
}
public boolean signUp() {
boolean done = !Username.equals("") && !Password.equals("") && !Password1.equals("") && Password.equals(Password1);
try {
if (done) {
DBConnection ToDB = new DBConnection(); //Have a connection to the DB
Connection DBConn = ToDB.openConn();
Statement Stmt = DBConn.createStatement();
String SQL_Command = "SELECT Username FROM Account WHERE Username ='"+Username+"'"; //SQL query command
ResultSet Rslt = Stmt.executeQuery(SQL_Command); //Inquire if the username exsits.
done = done && !Rslt.next();
if (done) {
SQL_Command = "INSERT INTO Account(Username, Password, Name) VALUES ('"+Username+ "','"+Password+"','"+Name+"')"; //Save the username, password and Name
Stmt.executeUpdate(SQL_Command);
}
Stmt.close();
ToDB.closeConn();
}
}
catch(java.sql.SQLException e)
{ done = false;
System.out.println("SQLException: " + e);
while (e != null)
{ System.out.println("SQLState: " + e.getSQLState());
System.out.println("Message: " + e.getMessage());
System.out.println("Vendor: " + e.getErrorCode());
e = e.getNextException();
System.out.println("");
}
}
catch (java.lang.Exception e)
{ done = false;
System.out.println("Exception: " + e);
e.printStackTrace ();
}
return done;
}
public String signIn()
{
boolean done = !Username.equals("") && !Password.equals("");
try
{
if (done)
{
DBConnection ToDB = new DBConnection(); //Have a connection to the DB
Connection DBConn = ToDB.openConn();
Statement Stmt = DBConn.createStatement();
String SQL_Command = "SELECT Name FROM Account WHERE Username ='"+Username+ "'AND Password ='"+Password+"'"; //SQL query command
ResultSet Rslt = Stmt.executeQuery(SQL_Command); //Inquire if the username and password exsits.
done = done && Rslt.next();
if (done)
{
Name=Rslt.getString(1);
}
Stmt.close();
ToDB.closeConn();
}
}
catch(java.sql.SQLException e)
{ done = false;
System.out.println("SQLException: " + e);
while (e != null)
{ System.out.println("SQLState: " + e.getSQLState());
System.out.println("Message: " + e.getMessage());
System.out.println("Vendor: " + e.getErrorCode());
e = e.getNextException();
System.out.println("");
}
}
catch (java.lang.Exception e)
{ done = false;
System.out.println("Exception: " + e);
e.printStackTrace ();
}
return Name;
}
public boolean changePassword(String NewPassword) { //5
boolean done = false;
try { //20
DBConnection ToDB = new DBConnection(); //Have a connection to the DB
Connection DBConn = ToDB.openConn();
Statement Stmt = DBConn.createStatement();
String SQL_Command = "SELECT * FROM Account WHERE Username ='"+Username+ "'AND Password ='"+Password+"'"; //SQL query command
ResultSet Rslt = Stmt.executeQuery(SQL_Command); //Inquire if the username exsits.
if (Rslt.next()) {
SQL_Command = "UPDATE Account SET Password='"+NewPassword+"' WHERE Username ='"+Username+"'"; //Save the username, password and Name
Stmt.executeUpdate(SQL_Command);
Stmt.close();
ToDB.closeConn();
done=true;
}
}
catch(java.sql.SQLException e) //5
{ done = false;
System.out.println("SQLException: " + e);
while (e != null)
{ System.out.println("SQLState: " + e.getSQLState());
System.out.println("Message: " + e.getMessage());
System.out.println("Vendor: " + e.getErrorCode());
e = e.getNextException();
System.out.println("");
}
}
catch (java.lang.Exception e)
{ done = false;
System.out.println("Exception: " + e);
e.printStackTrace ();
}
return done;
}
}