Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Example using Apache Common's DBCP library
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'")) {
} catch (SQLException ex) {
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.