Merge pull request #36 from EoD/trace-logs
add trace logs for all SQL queries
This commit is contained in:
commit
92e95a94a4
|
|
@ -4,8 +4,14 @@ import vip.fubuki.playersync.config.JdbcConfig;
|
||||||
|
|
||||||
import java.sql.*;
|
import java.sql.*;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
|
||||||
|
import com.mojang.logging.LogUtils;
|
||||||
|
|
||||||
public class JDBCsetUp {
|
public class JDBCsetUp {
|
||||||
|
|
||||||
|
private static final Logger LOGGER = LogUtils.getLogger();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a connection to the MySQL server.
|
* Returns a connection to the MySQL server.
|
||||||
* @param selectDatabase if true, the returned URL includes the configured database name.
|
* @param selectDatabase if true, the returned URL includes the configured database name.
|
||||||
|
|
@ -40,6 +46,7 @@ public class JDBCsetUp {
|
||||||
* Executes a query using a connection that includes the database.
|
* Executes a query using a connection that includes the database.
|
||||||
*/
|
*/
|
||||||
public static QueryResult executeQuery(String sql) throws SQLException {
|
public static QueryResult executeQuery(String sql) throws SQLException {
|
||||||
|
LOGGER.trace(sql);
|
||||||
Connection connection = getConnection(); // With database selected (and "USE" already run)
|
Connection connection = getConnection(); // With database selected (and "USE" already run)
|
||||||
PreparedStatement queryStatement = connection.prepareStatement(sql);
|
PreparedStatement queryStatement = connection.prepareStatement(sql);
|
||||||
ResultSet resultSet = queryStatement.executeQuery();
|
ResultSet resultSet = queryStatement.executeQuery();
|
||||||
|
|
@ -50,6 +57,7 @@ public class JDBCsetUp {
|
||||||
* Executes an update using a connection that includes the database.
|
* Executes an update using a connection that includes the database.
|
||||||
*/
|
*/
|
||||||
public static void executeUpdate(String sql) throws SQLException {
|
public static void executeUpdate(String sql) throws SQLException {
|
||||||
|
LOGGER.trace(sql);
|
||||||
try (Connection connection = getConnection()) { // With database selected
|
try (Connection connection = getConnection()) { // With database selected
|
||||||
try (PreparedStatement updateStatement = connection.prepareStatement(sql)) {
|
try (PreparedStatement updateStatement = connection.prepareStatement(sql)) {
|
||||||
updateStatement.executeUpdate();
|
updateStatement.executeUpdate();
|
||||||
|
|
@ -62,6 +70,7 @@ public class JDBCsetUp {
|
||||||
* This method is used for commands like "CREATE DATABASE IF NOT EXISTS ..."
|
* This method is used for commands like "CREATE DATABASE IF NOT EXISTS ..."
|
||||||
*/
|
*/
|
||||||
public static void executeUpdate(String sql, int dummy) throws SQLException {
|
public static void executeUpdate(String sql, int dummy) throws SQLException {
|
||||||
|
LOGGER.trace(sql);
|
||||||
try (Connection connection = getConnection(false)) { // Without default database
|
try (Connection connection = getConnection(false)) { // Without default database
|
||||||
try (PreparedStatement updateStatement = connection.prepareStatement(sql)) {
|
try (PreparedStatement updateStatement = connection.prepareStatement(sql)) {
|
||||||
updateStatement.executeUpdate();
|
updateStatement.executeUpdate();
|
||||||
|
|
@ -73,6 +82,7 @@ public class JDBCsetUp {
|
||||||
* A helper method for updates with parameters.
|
* A helper method for updates with parameters.
|
||||||
*/
|
*/
|
||||||
public static void update(String sql, String... argument) throws SQLException {
|
public static void update(String sql, String... argument) throws SQLException {
|
||||||
|
LOGGER.trace(sql);
|
||||||
try (Connection connection = getConnection()) { // With database selected
|
try (Connection connection = getConnection()) { // With database selected
|
||||||
PreparedStatement updateStatement = connection.prepareStatement(sql);
|
PreparedStatement updateStatement = connection.prepareStatement(sql);
|
||||||
for (int i = 0; i < argument.length; i++) {
|
for (int i = 0; i < argument.length; i++) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user