GithubHelp home page GithubHelp logo

mysql-api's Introduction

MySQL-API

Simple Java API for MySQL

Installation

Notice Version can be changed. You see the last version in the badge on top of this site

Maven

<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>

Gradle

allprojects {  
 repositories {  
  maven { url 'https://jitpack.io' }  
 }  
}  
 
dependencies {  
   implementation 'com.github.Tallerik:MySQL-API:2.0.1'  
}  

Usage

Init

MySQL sql = new MySQL();

Set Credentials

sql.setHost("localhost");
sql.setUser("sqluser");
sql.setPassword("sqlpassword");
sql.setDb("database");

sql.setPort(3306); // Optional. Default: 3306
sql.setDebug(false); // Optional. Default: false

Connect to MySQL

boolean: sql.connect();

Checks

boolean: isConnected();
boolean: isDebug();

MySQL Data interaction

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!

Result

List<Row> rowList = res.getRows();
for(Row r : rowList) {
    System.out.println(r.get("column1") + "   " + r.get("column2"));
}

Close Connection

sql.close();

mysql-api's People

Contributors

dependabot[bot] avatar tallerik avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

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.