My MySQL Manager System in Java menu

User Tag List

Results 1 to 1 of 1
  1. #1
    buyingrafwow's Avatar Banned
    Reputation
    7
    Join Date
    Oct 2012
    Posts
    105
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    My MySQL Manager System in Java

    Bit messy and could be edited a bit/not the best, but here we go...

    Things you will need
    EasyPHP - EasyPHP.org (For MySQL, Etc.)
    MySQL JDBC Connector - MySQL :: Download Connector/J

    Create a new file called "connection.java" and put this in it:

    Code:
    package mysql;
    import java.sql.*;
    
    public class connection {
    	//How to use the connURL Statement:
    	//jdbc:mysql// is needed by default
    	//127.0.0.1/ is the Host and can be edited to your URL, or just localhost
    	//usermaster is the database
    	private static final String connURL = "jdbc:mysql://127.0.0.1/hiscores";
    	
    	//Make our variables and set them all to null
    	private static Statement stmt;
    	private static ResultSet rs = null;
    	private static Connection conn = null;
    	private static String query = null;
    	private static boolean mysqlEnabled = true;
    	
    	public static synchronized void connect() {
    		try {
    			Class.forName("com.mysql.jdbc.Driver").newInstance();
    			//connURL : Explained Above
    			//root : Username for MySQL
    			//Empty space : Password for MySQL
    			conn = DriverManager.getConnection(connURL, "root", "");
    			System.out.println("Connected to MySQL Successfully");
    		} catch(Exception e) {
    			System.out.println("Error: Unable to connect to MySQL. Details below.");
    			System.out.println(e);
    			mysqlEnabled = false;
    		}
    	}
    	public static synchronized void close() {
    		try {
    			conn.close();
    			stmt.close();
    			System.out.println("Closed MySQL Successfully");
    		} catch(Exception e) {
    			System.out.println("No MySQL Connection");
    		}
    	}
    	public static synchronized void execute(String s) {
    		if(mysqlEnabled == true) {
    			try {
    				stmt = conn.createStatement();
    				query = s;
    				stmt.executeUpdate(query);
    				System.out.println("'"+query+"'");
    				System.out.println("MySQL: Query was a success.");
    			} catch(Exception e) {
    				System.out.println("Error: Unable to update MySQL. Error below.");
    				System.out.println(e);
    			}
    		} else {
    			System.out.println("MySQL is not currently being used.");
    		}
    	}
    }
    Editing stuff should be self explanitory

    Now, download and extract the MySQL JDBC Connector and copy/paste the "com" folder into your src directory
    You will get errors in the files, but you aren't using any of them so it doesn't matter. I suppose you could always delete all of them except the Driver.java in com/mysql/jdbc

    You are now done! But how do we use this code?

    In any new class, or the same class, put this:

    Code:
    connection conn = new connection();
    and then inside a void statement, or anything like that, put this:

    Code:
    conn.connect();
    conn.execute("QUERY HERE");
    conn.close();
    All this does is establishes your connection, updates the MySQL, and then abolishes it after the execute is done.

    You are now officially done!

    My MySQL Manager System in Java

Similar Threads

  1. [Misc] World of Warcraft: Private Server Content Management System (Feature Requests)
    By ev0 in forum World of Warcraft Emulator Servers
    Replies: 4
    Last Post: 05-03-2016, 03:20 PM
  2. Replies: 5
    Last Post: 01-19-2013, 05:35 AM
  3. [MySQL] System 1067 Error
    By Twiddles in forum WoW EMU Questions & Requests
    Replies: 2
    Last Post: 04-05-2010, 02:16 PM
  4. Vote reward System mysql bug
    By Dagster in forum WoW EMU Questions & Requests
    Replies: 0
    Last Post: 05-06-2009, 04:40 AM
All times are GMT -5. The time now is 07:39 PM. Powered by vBulletin® Version 4.2.3
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved. User Alert System provided by Advanced User Tagging (Pro) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
Google Authenticator verification provided by Two-Factor Authentication (Free) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
Digital Point modules: Sphinx-based search