54 lines
1.3 KiB
Java
Raw Normal View History

2019-10-03 08:42:09 +02:00
package com.wasteinformationserver.db;
import com.wasteinformationserver.basicutils.Log;
import com.wasteinformationserver.db.Database;
import com.wasteinformationserver.db.MySQLConnector;
2019-09-20 15:02:17 +02:00
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
public class jdcb {
2019-09-27 12:25:41 +02:00
Connection conn;
public jdcb(String username, String password, String dbName) {
2019-09-20 15:02:17 +02:00
Database db = new MySQLConnector(
username,
password,
"192.168.65.15",
2019-09-20 15:02:17 +02:00
3306,
dbName);
2019-09-20 15:02:17 +02:00
2019-10-03 08:42:09 +02:00
try {
conn = db.getConnection();
} catch (SQLException e) {
Log.error("no connection to Database! DB Server not started...?");
}
2019-09-27 12:25:41 +02:00
}
public ResultSet executeQuery(String sql) {
2019-09-20 15:02:17 +02:00
try {
2019-09-27 12:25:41 +02:00
PreparedStatement stmt = conn.prepareStatement(sql);
2019-09-20 15:02:17 +02:00
return stmt.executeQuery();
2019-09-20 15:02:17 +02:00
} catch (SQLException e) {
e.printStackTrace();
}
return null;
2019-09-20 15:02:17 +02:00
}
2019-09-27 12:25:41 +02:00
public int executeUpdate(String sql){
try {
PreparedStatement stmt = conn.prepareStatement(sql);
return stmt.executeUpdate();
} catch (SQLException e) {
e.printStackTrace();
}
return -1;
}
2019-09-20 15:02:17 +02:00
}