JDBC lint helps Java programmers write correct and efficient code when using the JDBC API. JDBC lint requires Java 6 and has no other run-time dependencies. Andrew Gaul at Maginatics email@example.com originally wrote JDBC lint.
JDBC lint warns about many different conditions:
Users can enable JDBC lint by wrapping Connection or DataSource objects:
import com.maginatics.jdbclint.Configuration; import com.maginatics.jdbclint.Configuration.Check; import com.maginatics.jdbclint.ConnectionProxy; ... Configuration config = new Configuration(EnumSet.allOf(Check.class), Arrays.<Configuration.Action>asList( Configuration.PRINT_STACK_TRACE_ACTION, Configuration.THROW_SQL_EXCEPTION_ACTION)); Connection connection = DriverManager.getConnection(...); connection = ConnectionProxy.newInstance(connection, config); connection.close(); connection.close(); // triggers error, runs Actions
Users can configure checks providing a different Set to the Configuration constructor. Users can also configure the actions JDBC lint takes when triggering a check by providing a different Collection. Sample actions include printing the stack trace to stderr or a File, throwing a SQLException or RuntimeException, or exiting.
To make use of JDBC lint in an Apache Maven based project, add it as a dependency:
<dependency> <groupId>com.maginatics</groupId> <artifactId>jdbclint</artifactId> <version>0.5.0</version> </dependency>
JDBC lint implements its checks by wrapping concrete implementations like Connection with dynamic proxy classes. This allows JDBC lint to add its checks before and after the concrete method invocation while preserving all behaviors of the original class. Some checks like warning about missing calls to close require use of finalization which depends on the behavior of Java garbage collection.
JDBC has significant complexity and other tools can help write correct code. Specifically FindBugs can detect failures to close SQL resources and Java 7 try-with-resources can prevent the same mistakes. JDBI offers an annotation-based approach to writing SQL which avoids some kinds of errors. jOOQ offers a fluent API that hides most interaction with JDBC from client code. JDBC lint can work in conjunction with all of these tools.
Copyright (C) 2012-2014 Maginatics, Inc.
Licensed under the Apache License, Version 2.0