Dillan's MySQL(ite) API GitHub This is a MySQL and SQLite API. How to Use: 1. Add all the files to your GitHub Project. 2. Use the API! 3. Put the following in your main class: NOTE: If you are using SQLite just leave the values like they are. Code: MySQL sql = new MySQL("host.name", "port", "database", "user", "pass"); MySQL Code: sql.open(); SQLite Code: sql.openLite(plugin, dbpath); Examples: Retrieving Values (JavaDocs) Code: ResultSet res = sql.query("SELECT * FROM users WHERE player='MCMatters'"); while(res.next()){ res.getString("player"); //Read the JavaDocs } Setting Information Code: sql.update("INSERT INTO players (`PlayerName`, `tokens`) VALUES ('MCMatters', '0');"); Prepared Statements Code: MySQLPrepared msp = sql.prepare("SELECT * FROM users WHERE player=? AND tokens=?"); //First arg is index and Second arg is the value. msp.setString(1, "PlayerName"); msp.setInt(2, 1); //There is also msp.setObject(index, new Object()); ----------------------------------- If you need help just comment down below!
@MCMatters Hey. Nice API, but I have a few questions. How does your api differ from this one, and is there any reason why I should use yours instead? https://bukkit.org/threads/using-mysql-in-your-plugins.132309/
@Assist Mine has a class for PreparedStatements and his is basically an api to connect to MySQL, mine has executeQuery/Update, Mine also doesn't have the unnecessary Class.forName that they put.
@MCMatters No offence, but I don't understand all the MySQL Utils. It's not that hard to do it yourself (and if you know what you're doing you can make it even faster, possibly more secure and/or more convenient for you) - Not directed at you necessarily, but yeah. Other than that, this is all right I guess.
Pretty sure Class.forName is sometimes necessary to load the drivers, according to Stackoverflow. https://bukkit.org/threads/using-mysql-in-your-plugins.132309/ This allows us to easily use the database management API built into Java... As you can see in the thread, the Statement class has the methods: execute, executeUpdate and executeQuery. Also, there's a class called PreparedStatement, and you can use: connection.prepareStatement. I honestly see absolutely no reason as to why not use that instead of this.
@KingFaris11 bukkit already loads the drivers and my PreparedStatement class is just a simpler way of PreparedStatements.
Ah right, didn't know it didn't. I still won't be using this, and probably many others, as PreparedStatement class already built in has all that I need, and is still as easy to use.