Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.PreparedStatement;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- import java.sql.Statement;
- /*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
- */
- /**
- *
- * @author John
- */
- public class SQL {
- Connection con = null;
- String dbHost = "";
- String dbUser = "";
- String dbPass = "";
- String dbSchema = "";
- public SQL() {
- Open();
- }
- public void Close() {
- try {
- con.close();
- }
- catch(Exception e) {
- }
- }
- public void Open() {
- try {
- Class.forName("com.mysql.jdbc.Driver").newInstance();
- con = DriverManager.getConnection("jdbc:mysql://" + dbHost + "/" + dbSchema, dbUser, dbPass);
- }
- catch(Exception e) {
- }
- }
- private void CheckOpen() {
- try {
- if(con == null || con.isClosed()) Open();
- }
- catch(Exception e) {
- }
- }
- public void Execute(String sql) {
- CheckOpen();
- try {
- Statement statement = con.createStatement();
- statement.execute(sql);
- }
- catch(Exception e) {
- }
- }
- public ResultSet GetResults(String sql) {
- CheckOpen();
- try {
- Statement statement = con.createStatement();
- return statement.executeQuery(sql);
- }
- catch(Exception e) {
- return null;
- }
- }
- public String Escape(String data) {
- return data.replaceAll("\'", "\\\'");
- }
- /*
- ResultSet r = sql.GetResults("");
- try {
- // Found?
- if(r.first()) {
- }
- else {
- }
- } catch (Exception e) {
- }
- */
- }
- /*
- */
- public void ReloadUser() {
- ResultSet r = sql.GetResults("SELECT wallet, isAdmin FROM User WHERE userName = \"" + this.eUserName + "\"");
- try {
- // Found?
- if(r.first()) {
- this.wallet = r.getInt("wallet");
- this.admin = r.getBoolean("isAdmin");
- }
- else {
- // Create user using database defaults
- this.newUser = true;
- sql.Execute("INSERT INTO User (userName) values (\"" + this.eUserName + "\")");
- ReloadUser();
- }
- } catch (Exception e) {
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement