Giter VIP home page Giter VIP logo

printablepreparedstatement's Introduction

Contents

PrintablePreparedStatement

Decorator for JDBC PreparedStatement, prints queries in readable format. Internal implementation of PreparedStatement is unchanged.

Installation

Copy the file into your project (jar and/or maven dependency may be coming in the future)

Usage

To instantiate

String query = "INSERT INTO table_name VALUES (?, ?, ?, ?)"
PrintablePreparedStatement ps = 
new PrintablePreparedStatement(connection.prepareStatement(query), query);

Where connection is an instance of java.sql.Connection

  • Any query can be passed as a parameter
  • With the default settings, calling ps.execute(), ps.executeQuery(), or ps.executeUpdate() will print the query before executing it

To instantiate with auto-printing turned off

String query = "INSERT INTO table_name VALUES (?, ?, ?, ?)"
PrintablePreparedStatement ps = 
new PrintablePreparedStatement(connection.prepareStatement(query), query, false);

To toggle auto-printing (application-wise)

PrintablePreparedStatement.autoPrint = false; // true by default

To print manually

System.out.println(ps.toString());

or

ps.print();

Sample Output

  • Code used

Screen Shot 2021-04-15 at 12 34 22 AM

  • Output

Screen Shot 2021-04-15 at 12 28 45 AM

Current working setters

setBoolean()
setShort()
setInt()
setString()
setLong()
setFloat()
setDouble()
setBigDecimal()
setDate()
setTime()
setTimestamp()
setObject() // the object's toString() method will be called.

Known issues

  • May not work if the table name or the attribute contains a '?'
  • Does not work with arrays or streams

Missing features?

  • Feel free to make an issue if a particular setter isn't printing properly, or if you'd like one that isn't listed above

printablepreparedstatement's People

Contributors

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