Skip to content

Commit cdee236

Browse files
author
xDabDoub
committed
Added More MySQL Queries.
1 parent 970709e commit cdee236

1 file changed

Lines changed: 101 additions & 5 deletions

File tree

src/main/java/io/github/simplexdev/simplexcore/sql/Database.java

Lines changed: 101 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,6 @@
66

77
public class Database {
88

9-
/*
10-
* More to be added soon.
11-
*/
12-
139
public static void createTable(String table, String columns) {
1410
PreparedStatement ps;
1511
try {
@@ -70,6 +66,106 @@ public static boolean exists(String table, String column, Object value) {
7066
return false;
7167
}
7268

69+
public static String getString(String table, String column, String gate, Object gate_value) {
70+
PreparedStatement ps;
71+
try {
72+
ps = MySQL.getConnection().prepareStatement("SELECT " + column + " FROM " + table
73+
+ " WHERE " + gate + "=?");
74+
ps.setObject(1, gate_value);
75+
76+
ResultSet rs = ps.executeQuery();
77+
String toReturn;
78+
79+
if (rs.next()) {
80+
toReturn = rs.getString(column);
81+
return toReturn;
82+
}
83+
} catch (SQLException ex) {
84+
// TODO
85+
}
86+
return null;
87+
}
88+
89+
public static int getInt(String table, String column, String gate, Object gate_value) {
90+
PreparedStatement ps;
91+
try {
92+
ps = MySQL.getConnection().prepareStatement("SELECT " + column + " FROM " + table
93+
+ " WHERE " + gate + "=?");
94+
ps.setObject(1, gate_value);
95+
96+
ResultSet rs = ps.executeQuery();
97+
int toReturn;
98+
99+
if (rs.next()) {
100+
toReturn = rs.getInt(column);
101+
return toReturn;
102+
}
103+
} catch (SQLException ex) {
104+
// TODO
105+
}
106+
return 0;
107+
}
108+
109+
public static Double getDouble(String table, String column, String gate, Object gate_value) {
110+
PreparedStatement ps;
111+
try {
112+
ps = MySQL.getConnection().prepareStatement("SELECT " + column + " FROM " + table
113+
+ " WHERE " + gate + "=?");
114+
ps.setObject(1, gate_value);
115+
116+
ResultSet rs = ps.executeQuery();
117+
double toReturn;
118+
119+
if (rs.next()) {
120+
toReturn = rs.getDouble(column);
121+
return toReturn;
122+
}
123+
} catch (SQLException ex) {
124+
// TODO
125+
}
126+
return null;
127+
}
128+
129+
public static long getLong(String table, String column, String gate, Object gate_value) {
130+
PreparedStatement ps;
131+
try {
132+
ps = MySQL.getConnection().prepareStatement("SELECT " + column + " FROM " + table
133+
+ " WHERE " + gate + "=?");
134+
ps.setObject(1, gate_value);
135+
136+
ResultSet rs = ps.executeQuery();
137+
long toReturn;
138+
139+
if (rs.next()) {
140+
toReturn = rs.getLong(column);
141+
return toReturn;
142+
}
143+
} catch (SQLException ex) {
144+
// TODO
145+
}
146+
return 0;
147+
}
148+
149+
public static byte getByte(String table, String column, String gate, Object gate_value) {
150+
PreparedStatement ps;
151+
try {
152+
ps = MySQL.getConnection().prepareStatement("SELECT " + column + " FROM " + table
153+
+ " WHERE " + gate + "=?");
154+
ps.setObject(1, gate_value);
155+
156+
ResultSet rs = ps.executeQuery();
157+
byte toReturn;
158+
159+
if (rs.next()) {
160+
toReturn = rs.getByte(column);
161+
return toReturn;
162+
}
163+
} catch (SQLException ex) {
164+
// TODO
165+
}
166+
return 0;
167+
}
168+
73169
public static Object get(String table, String column, String gate, Object gate_value) {
74170
PreparedStatement ps;
75171
try {
@@ -81,7 +177,7 @@ public static Object get(String table, String column, String gate, Object gate_v
81177
Object toReturn;
82178

83179
if (rs.next()) {
84-
toReturn = rs.getObject("CODE");
180+
toReturn = rs.getObject(column);
85181
return toReturn;
86182
}
87183
} catch(SQLException ex) {

0 commit comments

Comments
 (0)