-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDBCon.java
More file actions
179 lines (171 loc) · 6.99 KB
/
DBCon.java
File metadata and controls
179 lines (171 loc) · 6.99 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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author tarun gupta
*/
import java.sql.*;
import java.util.Calendar;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;
public class DBCon {
public static final String URL = "jdbc:mysql://localhost/PR3";
public static final String USER = "root";
public static final String PASS = "";
Connection con;
Statement st;
ResultSet rs ;
public DBCon(){
try {
try {
Class.forName("com.mysql.jdbc.Driver");
} catch (ClassNotFoundException ex) {
JOptionPane.showMessageDialog(null, ex.getMessage());
}
con = DriverManager.getConnection(URL,USER,PASS);
st = con.createStatement();
} catch (SQLException ex) {
JOptionPane.showMessageDialog(null, ex.getMessage());
}
}
public void category(String str) {
try {
st.executeUpdate("insert into category (cat_name) values('"+str+"')");
} catch (SQLException ex) {
JOptionPane.showMessageDialog(null, ex.getMessage());
}
}
public void editCategory(String str,int i){
try {
st.executeUpdate("update category set cat_name = '"+str+"' where cat_id = "+i+" ");
} catch (SQLException ex) {
JOptionPane.showMessageDialog(null, ex.getMessage());
}
}
int getCat_id(String query) {
try {
ResultSet rs = st.executeQuery(query);
if(rs.next())
return rs.getInt("cat_id");
} catch (SQLException ex) {
JOptionPane.showMessageDialog(null, ex.getMessage());
}
return 0;
}
public void addCourse(String cat_name,String cor_name,int fees,String desc){
try {
int id;
ResultSet rss = st.executeQuery("select cat_id from category where cat_name = '"+cat_name+"'");
if(rss.next()){
id = rss.getInt("cat_id");
st.executeUpdate("insert into course(cat_id,cor_name,fees,description) values('"+id+"','"+cor_name+"',"+fees+",'"+desc+"')");
}
} catch (SQLException ex) {
System.out.println(ex);
}
}
public ResultSet select(String q){
ResultSet rs=null;
try {
rs = st.executeQuery(q);
}
catch (SQLException ex) {
JOptionPane.showMessageDialog(null, ex.getMessage());
}
return rs;
}
public void enquiry(String roll,String name,String email,String gender,String college,String phone,
String duration,String coursename,String date,String time,String fees,String reference){
try {
st.executeUpdate("insert into enquiry values ('"+roll+"','"+name+"','"+email+"','"+gender+"' ,'"+college+"','"+phone+"','"+duration+"','"+coursename+"','"+date+"','"+time+"','"+fees+"','"+reference+"')");
} catch (SQLException ex) {
JOptionPane.showMessageDialog(null, ex.getMessage());
}
JOptionPane.showMessageDialog(null, "Submission Successful");
}
public int login(String username,String password){
try {
rs = st.executeQuery("select * from login1 where username = '"+username+"' and password = '"+password+"' ");
if(rs.next()){
return 1;
}
else{
rs = st.executeQuery("select * from login2 where username = '"+username+"' and password = '"+password+"'");
if(rs.next())
return 2;
}
} catch (SQLException ex) {
JOptionPane.showMessageDialog(null, ex.getMessage());
}
return 0;
}
public ResultSet selectTable(String query){
ResultSet rss=null;
try {
rss = st.executeQuery(query);
} catch (SQLException ex) {
JOptionPane.showMessageDialog(null, rss);
}
return rss;
}
public String registration(String roll,String query,String arg){
try {
rs = st.executeQuery(query);
if(rs.next()){
return rs.getString(arg);
}
} catch (SQLException ex) {
JOptionPane.showMessageDialog(null, ex.getMessage());
}
return "invalid";
}
public void registeringValues(String roll,String name,String father,String gender,String phone,String duration,String course,
String time,int totalfees,int discount,int paid,int remainfee,String query){
try {
Calendar cal = Calendar.getInstance();
int dat = cal.get(Calendar.DATE);
int month = cal.get(Calendar.MONTH) + 1;
int year = cal.get(Calendar.YEAR);
String date = "";
date = String.valueOf(year) +"-"+ String.valueOf(month) +"-" + String.valueOf(dat);
DBCon db = new DBCon();
st.executeUpdate(query);
st.executeUpdate("insert into transaction(roll,amountpaid,paymentleft,date) values('"+roll+"',"+paid+","+remainfee+",'"+date+"')");
} catch (SQLException ex) {
JOptionPane.showMessageDialog(null, ex.getMessage());
}
}
public void Updation(String roll,int amountpaid,int amountleft){
try {
Calendar cal = Calendar.getInstance();
int dat = cal.get(Calendar.DATE);
int month = cal.get(Calendar.MONTH) + 1;
int year = cal.get(Calendar.YEAR);
String date = "";
date = String.valueOf(year) +"-"+ String.valueOf(month) +"-" + String.valueOf(dat);
st.executeUpdate("insert into transaction(roll,amountpaid,paymentleft,date) values('"+roll+"',"+amountpaid+","+amountleft+",'"+date+"')");
} catch (SQLException ex) {
JOptionPane.showMessageDialog(null,ex.getMessage());
}
}
public void changePass(String user,String oldPass,String pass){
try {
rs = st.executeQuery("select * from login1 where username='"+user+"' and password='"+oldPass+"'");
if(rs.next()){
st.executeUpdate("update login1 set password='"+pass+"' where username='"+user+"'");
}
else{
rs = st.executeQuery("select * from login2 where username='"+user+"' and password='"+oldPass+"'");
if(rs.next()){
st.executeUpdate("update login1 set password='"+pass+"' where username='"+user+"'");
}
}
} catch (SQLException ex) {
JOptionPane.showMessageDialog(null, "Change password error");
}
}
}