forked from sanjana091001/bus_booking
-
Notifications
You must be signed in to change notification settings - Fork 0
/
user.java
61 lines (58 loc) · 1.38 KB
/
user.java
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
package bus_booking;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Scanner;
public class user {
Connection c = null;
Statement stmt = null;
String userid;
String pass;
user(String userid, String pass)
{
this.userid=userid;
this.pass=pass;
}
public
void addDetails()
{
try
{
Class.forName("org.postgresql.Driver");
c = DriverManager.getConnection("jdbc:postgresql://localhost:5432/bus_ticket_booking", "postgres", "postgres");
c.setAutoCommit(false);
stmt = c.createStatement();
String sql = "INSERT INTO (username, password) "
+ "VALUES("+userid+","+pass+");";
stmt.executeUpdate(sql);
System.out.println("Inserted successfully");
stmt.close();
}
catch (Exception e)
{
e.printStackTrace();
System.err.println(e.getClass().getName()+": "+e.getMessage());
System.exit(0);
}
}
void modifyDetails(String new_pass)
{
try
{
stmt = c.createStatement();
String sql = "UPDATE user set password="+new_pass+"where username="+userid+";";
stmt.executeUpdate(sql);
c.commit();
System.out.println("Updated Succesfully");
stmt.close();
}
catch (Exception e)
{
e.printStackTrace();
System.err.println(e.getClass().getName()+": "+e.getMessage());
System.exit(0);
}
}
}