www.jooq.org Open in urlscan Pro
2001:1600:4:11::3d  Public Scan

URL: https://www.jooq.org/hacking-jdbc
Submission: On February 13 via manual from RU — Scanned from CH

Form analysis 3 forms found in the DOM

Name: registration-emailPOST #

<form id="registration-email-form" name="registration-email" class="registration-email-form" action="#" method="POST">
  <div class="reg-row">
    <div class="reg-col reg-col-1">Name</div>
    <div class="reg-col reg-col-2"><input class="input" name="name"></div>
  </div>
  <div class="reg-row">
    <div class="reg-col reg-col-1">E-Mail</div>
    <div class="reg-col reg-col-2"><input class="input" name="email" type="email"></div>
  </div>
  <div class="reg-row">
    <div class="reg-col reg-col-1">Phone number</div>
    <div class="reg-col reg-col-2"><input class="input" name="phone" type="tel"></div>
  </div>
  <div class="reg-row">
    <div class="reg-col reg-col-1">Company Name</div>
    <div class="reg-col reg-col-2"><input class="input" name="company_name"></div>
  </div>
  <div class="reg-row">
    <div class="reg-col reg-col-1"> Anything else you'd like to tell us?<br> How did you hear from jOOQ?<br> What made you try jOOQ?<br> What are your expectations? </div>
    <div class="reg-col reg-col-2"><textarea name="comments"></textarea></div>
  </div>
  <div class="reg-row">
    <div class="reg-col reg-col-1">&nbsp;</div>
    <div class="reg-col reg-col-1">
      <button class="save"> Save </button>
    </div>
    <!--
    <div class="reg-col reg-col-1">
        <button class="no-thanks" data-cookie="jooq-registration-email" data-fade="email">
            No thanks
        </button>    
    </div>
	-->
  </div>
  <input type="hidden" id="registered-by" name="registered-by" value="newsletter-popup">
</form>

Name: registration-emailPOST #

<form id="registration-email-form" name="registration-email" class="registration-email-form" action="#" method="POST">
  <div class="reg-row">
    <div class="reg-col reg-col-1">Name</div>
    <div class="reg-col reg-col-2"><input class="input" name="name"></div>
  </div>
  <div class="reg-row">
    <div class="reg-col reg-col-1">E-Mail</div>
    <div class="reg-col reg-col-2"><input class="input" name="email" type="email"></div>
  </div>
  <div class="reg-row">
    <div class="reg-col reg-col-1">Phone number</div>
    <div class="reg-col reg-col-2"><input class="input" name="phone" type="tel"></div>
  </div>
  <div class="reg-row">
    <div class="reg-col reg-col-1">Company Name</div>
    <div class="reg-col reg-col-2"><input class="input" name="company_name"></div>
  </div>
  <div class="reg-row">
    <div class="reg-col reg-col-1"> Anything else you'd like to tell us?<br> How did you hear from jOOQ?<br> What made you try jOOQ?<br> What are your expectations? </div>
    <div class="reg-col reg-col-2"><textarea name="comments"></textarea></div>
  </div>
  <input type="hidden" id="registered-by" name="registered-by" value="oss-license">
</form>

Name: registration-emailPOST #

<form id="registration-email-form" name="registration-email" class="registration-email-form" action="#" method="POST">
  <div class="reg-row">
    <div class="reg-col reg-col-1">Name</div>
    <div class="reg-col reg-col-2"><input class="input" name="name"></div>
  </div>
  <div class="reg-row">
    <div class="reg-col reg-col-1">E-Mail</div>
    <div class="reg-col reg-col-2"><input class="input" name="email" type="email"></div>
  </div>
  <div class="reg-row">
    <div class="reg-col reg-col-1">Phone number</div>
    <div class="reg-col reg-col-2"><input class="input" name="phone" type="tel"></div>
  </div>
  <div class="reg-row">
    <div class="reg-col reg-col-1">Company Name</div>
    <div class="reg-col reg-col-2"><input class="input" name="company_name"></div>
  </div>
  <div class="reg-row">
    <div class="reg-col reg-col-1"> Anything else you'd like to tell us?<br> How did you hear from jOOQ?<br> What made you try jOOQ?<br> What are your expectations? </div>
    <div class="reg-col reg-col-2"><textarea name="comments"></textarea></div>
  </div>
  <input type="hidden" id="registered-by" name="registered-by" value="trial-license">
</form>

Text Content

 * Learn
 * Download / Pricing
 * Blog

All information from this page will be kept strictly confidential


TELL US A LITTLE BIT ABOUT YOURSELF AND JOIN OUR NEWSLETTER (EXAMPLES)



Name

E-Mail

Phone number

Company Name

Anything else you'd like to tell us?
How did you hear from jOOQ?
What made you try jOOQ?
What are your expectations?

 
Save

 


WE'RE HACKING JDBC...


... SO YOU DON'T HAVE TO


CODE THAT YOU DON'T WANT TO WRITE...


HOW TO FETCH GENERATED KEYS IN SOME DBS


case DERBY:
case H2:
case MARIADB:
case MYSQL: {
    try {
        listener.executeStart(ctx);
        result = ctx.statement().executeUpdate();
        ctx.rows(result);
        listener.executeEnd(ctx);
    }

    // Yes. Not all warnings may have been consumed yet
    finally {
        consumeWarnings(ctx, listener);
    }

    // Yep. Should be as simple as this. But it isn't.
    rs = ctx.statement().getGeneratedKeys();

    try {
        List<Object> list = new ArrayList<Object>();

        // Some JDBC drivers seem to illegally return null
        // from getGeneratedKeys() sometimes
        if (rs != null) {
            while (rs.next()) {
                list.add(rs.getObject(1));
            }
        }

        // Because most JDBC drivers cannot fetch all
        // columns, only identity columns
        selectReturning(ctx.configuration(), list.toArray());
        return result;
    }
    finally {
        JDBCUtils.safeClose(rs);
    }
}


HOW TO FETCH GENERATED KEYS IN OTHER DBS



// [#2744] DB2 knows the SELECT .. FROM FINAL TABLE (INSERT ..) syntax
case DB2:

// Firebird and Postgres can execute the INSERT .. RETURNING
// clause like a select clause. JDBC support is not implemented
// in the Postgres JDBC driver
case FIREBIRD:
case POSTGRES: {
    try {
        listener.executeStart(ctx);
        rs = ctx.statement().executeQuery();
        listener.executeEnd(ctx);
    }
    finally {
        consumeWarnings(ctx, listener);
    }

    break;
}


HOW FETCH ALL EXCEPTIONS IN SQL SERVER


switch (configuration.dialect().family()) {
    case SQLSERVER:
        consumeLoop: for (;;)
            try {
                if (!stmt.getMoreResults() &&
                     stmt.getUpdateCount() == -1)
                    break consumeLoop;
            }
            catch (SQLException e) {
                previous.setNextException(e);
                previous = e;
            }
}


INLINING BOOLEAN LITERALS


// [#1153] Some dialects don't support boolean literals
// TRUE and FALSE
if (asList(ASE, DB2, FIREBIRD, ORACLE,
           SQLSERVER, SQLITE, SYBASE).contains(family)) {
    context.sql(((Boolean) val) ? "1" : "0");
}
else {
    context.keyword(((Boolean) val).toString());
}


HOW TO DESERIALISE LOBS FROM UDTS


// [#1327] Oracle cannot deserialise BLOBs as byte[] from SQLInput
if (dataType.isLob()) {
    Blob blob = null;
    try {
        blob = stream.readBlob();
        return (T) (blob == null ? null :
                    blob.getBytes(1, (int) blob.length()));
    }
    finally {
        safeFree(blob);
    }
}
else {
    return (T) stream.readBytes();
}


HOW TO SERIALISE LOBS TO UDTS


// [#1327] Oracle cannot serialise BLOBs as byte[] to SQLOutput
// Use reflection to avoid dependency on OJDBC
if (dataType.isLob()) {
    Blob blob = null;

    try {
        blob = on("oracle.sql.BLOB").call("createTemporary",
                   on(stream).call("getSTRUCT")
                             .call("getJavaSqlConnection").get(),
                   false,
                   on("oracle.sql.BLOB").get("DURATION_SESSION")
               ).get();

        blob.setBytes(1, (byte[]) value);
        stream.writeBlob(blob);
    }
    finally {
        DefaultExecuteContext.register(blob);
    }
}
else {
    stream.writeBytes((byte[]) value);
}


HOW TO HANDLE BIGINTEGER AND BIGDECIMAL


else if (type == BigInteger.class) {
    // The SQLite JDBC driver doesn't support BigDecimals
    if (ctx.configuration().dialect() == SQLDialect.SQLITE) {
        return Convert.convert(rs.getString(index),
                               (Class) BigInteger.class);
    }
    else {
        BigDecimal result = rs.getBigDecimal(index);
        return (T) (result == null ? null :
                    result.toBigInteger());
    }
}
else if (type == BigDecimal.class) {
    // The SQLite JDBC driver doesn't support BigDecimals
    if (ctx.configuration().dialect() == SQLDialect.SQLITE) {
        return Convert.convert(rs.getString(index),
                               (Class) BigDecimal.class);
    }
    else {
        return (T) rs.getBigDecimal(index);
    }
}


INLINING DATE LITERALS


// The SQLite JDBC driver does not implement the escape syntax
// [#1253] SQL Server and Sybase do not implement date literals
if (asList(ASE, SQLITE, SQLSERVER, SYBASE).contains(family)) {
    context.sql("'").sql(escape(val)).sql("'");
}

else if (asList(ACCESS).contains(family)) {
    context.sql("#")
           .sql(new SimpleDateFormat("yyyy/MM/dd")
                    .format((Date) val))
           .sql("#");
}

// [#1253] Derby doesn't support the standard literal
else if (family == DERBY) {
    context.keyword("date('").sql(escape(val)).sql("')");
}

// Most dialects implement SQL standard date literals
else {
    context.keyword("date '").sql(escape(val)).sql("'");
}


WE COULD GO ON FOR HOURS...


... OR YOU JUST GO AHEAD AND


Download Your Free jOOQ Trial Now!


IMAGE COPYRIGHT INFORMATION

The above images were used with permission from various sources:

 * Cables: Matthew Straubmuller. License: CC-BY SA 2.0
 * Cables: Greg Grossmeier. License: CC-BY SA 2.0.
 * Electric Engineers: Marco Sarli. All rights reserved. Explicit permission
   granted.



↑ Back to top


COMMUNITY

 * Our customers
 * Tech Blog
 * Business Blog
 * GitHub
 * Stack Overflow
 * Activities
 * jOOQ Tuesdays


SUPPORT

 * User Groups
 * Reddit /r/jOOQ
 * Trainings
 * Contact
 * Bluesnap Account Login


LEGAL

 * Licenses
 * Privacy Policy
 * Terms of Service
 * Contributor Agreement


DOCUMENTATION

 * FAQ
 * Tutorial
 * The manual (single page)
 * The manual (multi page)
 * The manual (PDF)
 * Javadoc
 * Using SQL in Java is simple!
 * Convince your manager!
 * Our other products
 * Translate SQL between databases
 * Generate a diff between schemas
 * How to pronounce jOOQ

© 2009 - 2024 by Data Geekery™ GmbH. All rights reserved.
jOOQ™ is a trademark of Data Geekery GmbH. All other trademarks and copyrights
are the property of their respective owners.


REGISTRATION (OPTIONAL)

Name

E-Mail

Phone number

Company Name

Anything else you'd like to tell us?
How did you hear from jOOQ?
What made you try jOOQ?
What are your expectations?



LICENSE AGREEMENT

By downloading the jOOQ Community Edition, you confirm to have read and that you
agree to the terms of the Apache Software License 2.0.

I do not agree I agree


REGISTRATION (OPTIONAL)

Name

E-Mail

Phone number

Company Name

Anything else you'd like to tell us?
How did you hear from jOOQ?
What made you try jOOQ?
What are your expectations?



OTHER DISTRIBUTIONS

The free trial supports Java 8. If you would like to try the jOOQ for Java 11 or
Java 17 distributions, please use the downloads from /download/versions or
contact sales@datageekery.com.


LICENSE AGREEMENT

By downloading a 30 day trial license for the jOOQ Professional Edition or the
jOOQ Enterprise Edition, you confirm to have read and that you agree to the
terms of the jOOQ License.

I do not agree I agree


LICENSE AGREEMENT

By purchasing the jOOQ Express Edition, the Professional Edition, or the jOOQ
Enterprise Edition, you confirm to have read and that you agree to the terms of
the jOOQ License

If you prefer to purchase jOOQ Enterprise Edition licenses by purchase order /
invoice, please contact sales@datageekery.com or one of our preferred resellers
to get a quote.

I do not agree I agree
Sign up for our newsletter Maybe later

Help