GithubHelp home page GithubHelp logo

hog's Introduction

hog

Java JDBC library to return json style data from Database, compatible with Java 5 and upward.

Usage

This library is in Alpha. Expect breaking changes.

Maven Coordinates

hog is not on any public Maven repo yet, so you should run mvn clean install to install in the local repo.

Use the following Maven coordinates to include in your project.

  <dependencies>
    <dependency>
      <groupId>com.sougata</groupId>
      <artifactId>hog</artifactId>
      <version>0.2.0-SNAPSHOT</version>
    </dependency>
  </dependencies>

Example

Interface-based API

The following example shows the usage of interface based API.

public class HogExample{
    private DataSource ds;

    public HogExample() {
        BasicDataSource ds = new BasicDataSource();
        ds.setDriverClassName("com.mysql.jdbc.Driver");
        ds.setUsername("root");
        ds.setPassword("");
        ds.setUrl("jdbc:mysql://localhost:3306/mydb");
        this.ds = ds;
    }

    public void executeSQL() {

        DBHandler _handler = DBHandlerFactory.open(ds);
        _handler.execute("INSERT INTO emp(id,name,salary) values(4,'Sougata',300)");

    }
    public void executeCreateTable() {
        DBHandler _handler = DBHandlerFactory.open(ds);
        _handler.execute("CREATE TABLE dept(name varchar(20));");
    }

    public void executeSQLWithParameter() {

        DBHandler _handler = DBHandlerFactory.open(ds);
        _handler.execute("INSERT INTO emp(id,name,salary) values(?,?,?)", new Integer(5), "Sougata", new Integer(340));

    }

    public void retrieve() {

        DBHandler _handler = DBHandlerFactory.open(ds);
        String jsonValue = _handler.retrieve("Select id,name,salary from emp");
        

    }

    public void retrieveWithParameter() {

        DBHandler _handler = DBHandlerFactory.open(ds);
        String jsonValue = _handler.retrieve("Select * from emp where id=?", new Integer(1));
        
    }

    public void updateWithParameter() {
        DBHandler _handler = DBHandlerFactory.open(ds);
        _handler.execute("Update emp set dob=? where id=?", new java.util.Date(), new Integer(1));

    }

    

    public void insert() {
        DBHandler _handler = DBHandlerFactory.open(ds);
        _handler.insert("INSERT INTO dept(name) values(?)", "IT");
    }

    public void update() {
        DBHandler _handler = DBHandlerFactory.open(ds);
        _handler.insert("update emp set dob=? where id=?", new java.util.Date(), new Integer(2));
    }


}

License

Copyright © 2014 Sougata Bhattacharya

Distributed under the Eclipse Public License either version 1.0 or (at your option) any later version.

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.