-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDataBaseHandler.java
29 lines (23 loc) · 1.15 KB
/
DataBaseHandler.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
import java.sql.*;
public class DataBaseHandler extends ConfigsDb {
Connection dbConnection;
int idFromMixFood = 0;
public Connection getDbConnection () throws SQLException {
String connString = "jdbc:mysql://" + dbHost + ":" + dbPort + "/" + dbName + dbTimeZone; //connection parameters string using JDBC
dbConnection = DriverManager.getConnection(connString, dbUser, dbPass);
return dbConnection;
}
// CRUD - querie
public int selectIdIf (String sqlMorningFood, String sqlEveningFood, String sqlWater) throws SQLException {
String strSelectDogFood = "SELECT id FROM " + ConstDb.USER_TABLE + " WHERE "
+ ConstDb.MIXFOOD_MORNING + " = " + "'" + sqlMorningFood + "'" + " AND "
+ ConstDb.MIXFOOD_EVENING + " = " + "'" + sqlEveningFood + "'" + " AND "
+ ConstDb.MIXFOOD_WATER + " = " + "'" + sqlWater + "'";
Statement stmt = getDbConnection().createStatement();
ResultSet rset = stmt.executeQuery(strSelectDogFood);
while (rset.next()) {
idFromMixFood = rset.getInt(ConstDb.MIXFOOD_ID);
}
return idFromMixFood;
}
}