Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private boolean mysql_init() {
- try {
- new File("plugins" + File.separator + "authx60").mkdir();
- File cfile = new File("plugins" + File.separator + "authx60" + File.separator + "config.yml");
- if(!cfile.exists())
- cfile.createNewFile();
- Configuration config = new Configuration(cfile);
- config.load();
- String db_host = config.getString("database.host");
- String db_user = config.getString("database.user");
- String db_pass = config.getString("database.pass");
- String db_name = config.getString("database.name");
- if(db_host == null)
- db_host = "localhost";
- if(db_user == null)
- db_user = "root";
- if(db_pass == null)
- db_pass = "";
- if(db_name == null)
- db_name = "minecraft";
- Class.forName("com.mysql.jdbc.Driver");
- con = DriverManager.getConnection("jdbc:mysql://"+db_host+"/"+db_name, db_user, db_pass);
- return true;
- } catch ( Exception e ) {
- e.printStackTrace();
- return false;
- }
- }
- public List<Map<String,String>> mysql_select(String query) {
- mysql_init();
- ResultSet rs = null;
- List<Map<String, String>> result = new ArrayList<Map<String, String>>();
- try {
- Statement stmt = con.createStatement();
- rs = stmt.executeQuery(query);
- ResultSetMetaData rsmd = rs.getMetaData();
- while (rs.next()) {
- Map<String, String> temp = new HashMap<String, String>();
- for(int i = 1; i <= rsmd.getColumnCount(); i++)
- temp.put(rsmd.getColumnLabel(i), rs.getString(i));
- result.add(temp);
- }
- stmt.close();
- } catch (SQLException e) {
- e.printStackTrace();
- }
- mysql_disconnect();
- con = null;
- return result;
- }
- public void mysql_update(String query) {
- mysql_init();
- try {
- Statement stmt = con.createStatement();
- stmt.execute(query);
- stmt.close();
- } catch (SQLException e) {
- e.printStackTrace();
- }
- mysql_disconnect();
- con = null;
- }
- private void mysql_disconnect() {
- try {
- con.close();
- } catch(SQLException e) {
- e.printStackTrace();
- }
- }
Add Comment
Please, Sign In to add comment