Skip to content

Easy and intuitive MySQL interface for Java

aburkov edited this page Jun 27, 2015 · 1 revision

xpresso has the most simple and easy to understand interface with MySQL in Java.

String host = "host:port";
String user = "user";
String password = "password";
String db = "db";

try (HappySQL sql = x.mysql(host, user, password, db)) {
	try (HappySQL sql2 = x.mysql(sql)){
		String query =	"SELECT ID FROM " +
						"tbl_Employees e " +
						"WHERE e.Name LIKE ?";
		for (tuple row : sql.execute(query, "John %")) {
			query =	"UPDATE tbl_Employees " +
					"SET Promoted = 1 " +
					"WHERE ID = ?";
			sql2.execute(query, row.get("ID"));
		}
	}
}