Code Monkey home page Code Monkey logo

minesqlapi's Introduction

MineSQLAPI

API for making the integration of MySQL into Bukkit plugins quick and easy. If you find a bug or have an improvement, I'd love to hear.

Maven Info:

<repository>
	<id>aerenserve-repo</id>
	<url>http://repo.aerenserve.net</url>
</repository>

<dependency>
	<groupId>net.aerenserve</groupId>
	<artifactId>minesqlapi</artifactId>
	<version>1.3</version>
</dependency>

Features

  • Querying the MySQL database with traditional MySQL syntax
  • Executing updates to the MySQL database with traditional MySQL syntax
  • Creating a table
  • Opening a table as an ArrayList<HashMap<String, String>>
  • Getting a value from a certain row and column
  • Putting lots of values in a table by using String arrays.

Usage

First, we need to make a new MineSQL instance.

//Creating a new MineSQL instance

minesql = new MineSQL(this, "localhost", "3306", "exampleDatabase", "yourUser", "1337p4ssw0rd");

By using this constructor for a Table, we can create a new table.

//Example of making a new table

HashMap<String, String> columns = new HashMap<String, String>();
columns.put("username", "text");
columns.put("firstjoined", "text");

Table myTable = new Table(minesql, "exampleTable", columns);

You can put multiple values in a table at once.

//Example of putting values into a table

String username = "Notch";
String firstJoined = "1337";

if(!myTable.contains("username", username) { //Make sure that the value is not in the database
	String[] columns = {"username", "firstjoined"};
	String[] values = {e.getPlayer().getName(), String.format("" + e.getPlayer().getFirstPlayed())};
	myTable.insert(columns, values);
}

By using Table.openTable(), you can read and iterate through the values in a table

//Example of iterating through values in a table

ArrayList<HashMap<String, String>> table = myTable.openTable();
for(HashMap<String, String> hm : table) {
	Iterator<Entry<String, String>> it = hm.entrySet().iterator();
	  while (it.hasNext()) {
		Map.Entry<String, String> entry = (Entry<String, String>) it.next();
		System.out.println(entry.getKey() + " : " + entry.getValue());
	}
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.