50 lines
1.2 KiB
Java
Raw Normal View History

2019-10-03 08:42:09 +02:00
package com.wasteinformationserver.db;
import com.wasteinformationserver.basicutils.Log;
2019-09-20 15:02:17 +02:00
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
2019-11-08 10:42:22 +01:00
public class JDCB {
2019-10-11 09:03:14 +02:00
Connection conn;
2019-11-08 10:42:22 +01:00
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,
2019-10-04 16:52:14 +02:00
dbname);
2019-09-20 15:02:17 +02:00
2019-10-03 08:42:09 +02:00
try {
conn = db.getConnection();
} catch (SQLException e) {
2019-10-04 16:52:14 +02:00
Log.error("no connection to Database!");
2019-10-03 08:42:09 +02:00
}
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);
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
2019-10-11 09:03:14 +02:00
public int executeUpdate(String sql) {
2019-09-27 12:25:41 +02:00
try {
PreparedStatement stmt = conn.prepareStatement(sql);
return stmt.executeUpdate();
} catch (SQLException e) {
e.printStackTrace();
}
return -1;
}
2019-09-20 15:02:17 +02:00
}