Skip to content

virajprakash/sql-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Java MySQL API

This library allows for making basic queries and updates to a database on the fly. It is extremely easy and simple to use.

How to use

Below are the very basics on how to use the library.

Connect to database

MySQL database = new MySQL("localhost", "3306", "database", "username", "password");
if (database.connect()) {
//Do something here
}

Select from table

String select = database.select(Arrays.asList("username", "password"), "Accounts", "email");
MySQLResponse response = database.executeQuery(select, "me@virajprakash.com");
response.closeAll();

This would run the following query:

SELECT username, password FROM Accounts WHERE email = "me@virajprakash.com";

Insert into table

String insert = database.insert("Accounts", 3);
MySQLResponse response = database.executeUpdate(insert, "me@virajprakash.com", "Viraj", "password");
response.closeAll();

This would run the following query:

INSERT INTO Accounts VALUES ("me@virajprakash.com", "Viraj", "password");

Update rows in a table

String update = database.update("Accounts", Arrays.asList("email", "password"), "username");
MySQLResponse response = database.executeUpdate(update, "me@virajprakash.com", "password123", "Viraj");
response.closeAll();

This would run the following query:

UPDATE Accounts SET email = "me@virajprakash.com", password = "password123" WHERE username = "Viraj";

Count values in a table

String count = database.count("Accounts", "Email");
MySQLResponse response = database.executeQuery(count, "me@virajprakash.com");
int result = database.getCount(response);
response.closeAll();

This would run the following query:

SELECT COUNT(*) AS count FROM Accounts WHERE Email = "me@virajprakash.com";

About

A simple API to make queries and updates to a MySQL Database on the fly!

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages