Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package me.senzuri.SMod;
- import java.sql.DriverManager;
- import java.sql.Connection;
- import java.sql.PreparedStatement;
- public class SModMySQL
- {
- protected Connection con = null;
- protected PreparedStatement stmt = null;
- protected boolean connected = false;
- //Constructor
- public static SMod plugin;
- // Prepare SQL Statement + Connect to SQL
- public SModMySQL(SMod instance)
- {
- plugin = instance;
- try {
- Class.forName("com.mysql.jdbc.Driver").newInstance();
- // try to connect
- String url = "jdbc:mysql://localhost/minecraft";
- String user = plugin.ConfigHandler.username;
- String pass = plugin.ConfigHandler.password;
- if(user == null || pass == null) {
- this.con = DriverManager.getConnection(url);
- } else {
- this.con = DriverManager.getConnection(url, user, pass);
- }
- this.stmt = this.con.prepareStatement("INSERT INTO `test` (`player`, "
- + "`ip`) "
- + "VALUES (?, ?)");
- this.connected = true;
- }
- catch(java.lang.ClassNotFoundException ex) {
- System.out.println("ERROR: can`t load database driver");
- System.out.println(ex.getMessage());
- }
- catch(java.lang.InstantiationException ex) {
- System.out.println("ERROR: can`t load database driver");
- System.out.println(ex.getMessage());
- }
- catch(java.lang.IllegalAccessException ex) {
- System.out.println("ERROR: can`t load database driver");
- System.out.println(ex.getMessage());
- }
- catch(java.sql.SQLException sqlex) {
- System.out.println("ERROR: can`t connect to the database");
- System.out.println(sqlex.getMessage());
- }
- }
- public void SendSQL(String player, String ip)
- {
- try {
- this.stmt.setString(1, player);
- this.stmt.setString(2, ip);
- this.stmt.execute();
- }
- catch(java.sql.SQLException ex) {
- System.out.println(ex.getMessage());
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement