Simple Java API for MySQL
Notice Version can be changed. You see the last version in the badge on top of this site
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>com.github.Tallerik</groupId>
<artifactId>MySQL-API</artifactId>
<version>2.0.1</version>
</dependency>
</dependencies>
allprojects {
repositories {
maven { url 'https://jitpack.io' }
}
}
dependencies {
implementation 'com.github.Tallerik:MySQL-API:2.0.1'
}
MySQL sql = new MySQL();
sql.setHost("localhost");
sql.setUser("sqluser");
sql.setPassword("sqlpassword");
sql.setDb("database");
sql.setPort(3306); // Optional. Default: 3306
sql.setDebug(false); // Optional. Default: false
boolean: sql.connect();
boolean: isConnected();
boolean: isDebug();
Default way
boolean: sql.tableInsert("myTable", "name, age", "Robert", "32"); // INSERT Statement
boolean: sql.rowUpdate("myTable", new UpdateValue("age", "45"), "name = 'Robert'"); // UPDATE Statement
Result: sql.rowSelect("myTable", "*", "name = 'Robert'"); // SELECT Statement
boolean: sql.custom("DELETE * FROM myTable;"); // Custom SQL Statement
Request builder
// sql.tableInsert();
Insert ins = new Insert();
ins.setTable("myTable");
ins.setColumns("column1, column2");
ins.setData("value1", "value2");
boolean: sql.tableInsert(ins); // Multiple Builders accepted (sql.tableInsert(ins, ins2, ins3)
// sql.rowUpdate();
Update up = new Update();
up.setTable("myTable");
up.setValue(new UpdateValue("column1", "value3"));
up.setFilter("column2 = 'value2'");
boolean: sql.rowUpdate(up); // Multiple Builders accepted (sql.rowUpdate(up, up2, up3)
// sql.rowSelect();
Select select = new Select();
select.setTable("myTable");
select.setColumns("*"); // Optional default '*'
select.setFilter(""); // Optional default ''
Result: sql.rowSelect(select); // Only one Builder accepted!
List<Row> rowList = res.getRows();
for(Row r : rowList) {
System.out.println(r.get("column1") + " " + r.get("column2"));
}
sql.close();