This plugin is a library to use mysql-databases for bukkit plugins.
Features
- connect to a mysql server/database
- perform querys with and without return values
- if the connection is closed it will reconnect automatically
- mysql_real_escape_string function for better security
Javadoc:
Example
try { mysql = new MySQL(Bukkit.getLogger(), // logger "[ExamplePlugin] ", // prefix "localhost", // host 3306, // port "minecraft", // db "root", // user "" // pw); mysql.open(); if (mysql.isOpen()) // Check if the Connection was successful mysql.query("CREATE TABLE IF NOT EXISTS `regionen` ( `id` varchar(20) NOT NULL) ENGINE=MyISAM DEFAULT CHARSET=utf8;"); else Bukkit.getLogger().severe("[ExamplePlugin] Can't create connection"); } [...] public static String getOwner(String region) { try { ResultSet result = mysql.query("SELECT owner FROM region WHERE id = " + mysql.quote(region) + " LIMIT 1;"); if (result != null) { while (result.next()) { return result.getString("besitzer"); } } } catch (SQLException e) { Bukkit.getLogger().severe(e.getMessage()); } return null; }
Please report problems with this plugin!