package ru.alastar.database;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
public class DatabaseClient {
public static Connection conn = null;
public static void Start() throws InstantiationException,
IllegalAccessException, ClassNotFoundException {
try {
Class.forName("com.mysql.jdbc.Driver").newInstance();
conn = DriverManager
.getConnection("jdbc:mysql://localhost/theeder?"
+ "user=root&password=");
} catch (SQLException ex) {
System.out.println("SQLException: " + ex.getMessage());
System.out.println("SQLState: " + ex.getSQLState());
System.out.println("VendorError: " + ex.getErrorCode());
}
}
public static ResultSet commandExecute(String cmd) {
PreparedStatement stmt = null;
ResultSet rs = null;
try {
stmt = conn.prepareStatement(cmd);
if (stmt.execute(cmd)) {
rs = stmt.getResultSet();
}
return rs;
} catch (SQLException ex) {
System.out.println("SQLException: " + ex.getMessage());
System.out.println("SQLState: " + ex.getSQLState());
System.out.println("VendorError: " + ex.getErrorCode());
return null;
}
}
}