Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Example using Apache Common's DBCP library
//See https://github.com/ColbyLeclerc/blog-connection-pools/blob/master/src/main/java/Main.java
import database.DBCPDatabase;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
public class Main {
public static void main(String[] args) {
//Note Java 8's 'try-catch' automatically closes the connection and statement via an internal 'finally' block
try (Connection conn = DBCPDatabase.getDataSource().getConnection();
PreparedStatement statement = conn.prepareStatement("UPDATE TestTable SET Username = 'new_username'")) {
statement.execute();
} catch (SQLException ex) {
ex.printStackTrace();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.