-
Notifications
You must be signed in to change notification settings - Fork 2
/
GuiQuery3.java
85 lines (79 loc) · 2.91 KB
/
GuiQuery3.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
package dbms;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.Calendar;
import java.awt.BorderLayout;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;
/**
* Created by Saksham on 11/29/2016.
*/
public class GuiQuery3 {
JPanel base=new JPanel(new FlowLayout(FlowLayout.CENTER));
DefaultTableModel model;
JTable table;
JPanel centre;
public void query3gui(JPanel westbottom,JPanel centr){
westbottom.removeAll();
this.centre=centr;
centre.removeAll();
centre.repaint();
centre.revalidate();
westbottom.revalidate();
westbottom.repaint();
model = new DefaultTableModel();
model.addColumn("DrugId");
model.addColumn("Name");
model.addColumn("Quantity");
model.addColumn("Price");
model.addColumn("Location");
model.addColumn("Expiry");
table = new JTable(model);
centre.setLayout(new BorderLayout());
Connection connect = null;
Statement statement = null;
PreparedStatement preparedStatement = null;
ResultSet resultSet = null;
centre.add( new JScrollPane( table ), BorderLayout.CENTER );
try{
Class.forName("com.mysql.jdbc.Driver");
connect = DriverManager.getConnection("jdbc:mysql://localhost/dbms?"+"user=root&password=pass");
statement = connect.createStatement();
resultSet = statement.executeQuery("SELECT * FROM Drug1 NATURAL JOIN Drug2");
while(resultSet.next()){
String s = resultSet.getString("Expiry");
int exmonth = Integer.parseInt(s.split("/",2)[0]);
int exyear = Integer.parseInt(s.split("/",2)[1])+2000;
int month = Calendar.getInstance().get(Calendar.MONTH);
int year = Calendar.getInstance().get(Calendar.YEAR);
if(((year==exyear) && (exmonth - month)<=6) && (exmonth>month) || ((year==exyear-1) && (exmonth-month<=-6))){
model.addRow(new Object[]{resultSet.getString("Drug_ID"),resultSet.getString("Name"),resultSet.getString("Stock"),resultSet.getString("MRP"),resultSet.getString("Location"),resultSet.getString("Expiry")});
centre.repaint();
centre.revalidate();
}
}
if (resultSet != null) {
resultSet.close();
}
if (statement != null) {
statement.close();
}
if (connect != null) {
connect.close();
}
}catch(Exception e){
System.out.println(e);
}
centre.repaint();
centre.revalidate();
}
}