Code That Made Me Cry, #CTMMC™

95% of all code makes me cry. The other 5% are white space.

How to Call Stored Procedures (Java, #7 / 50)

// Using implementation-dependent JPA 2.0
StoredProcedureCall storedProcedureCall = new StoredProcedureCall();
DataReadQuery query = new DataReadQuery();
List<Object> argumentValues = new ArrayList<Object>();
Session session = jpaEntityManager.getActiveSession();
List<?> results = 
    (List<?>) session.executeQuery(query, argumentValues);
DatabaseRecord record = (DatabaseRecord) results.get(0);
String result = String.valueOf(record.get("o_output_1"));

// Using implementation-independent JPA 2.1
StoredProcedureQuery query = getEntityManager()
    "i_input_1", String.class, ParameterMode.IN);
    "o_output_1", String.class, ParameterMode.OUT);
query.setParameter("i_input_1", "valueOf_i_input_1");
boolean queryResult = query.execute();
String result = String.valueOf(

Calling stored procedures can be such a pain using JDBC or JEE's standard approaches as pointed out by Malcolm Boekhoff in his Stack Overflow answer:


comments powered by Disqus

Submit your own Code That Made You Cry

Send us your own example of code that made you cry! Please include:

Send the above to All accepted submissions will be licensed as CC BY-SA 3.0. Submit only code of a compatible license.

Note that we may choose not to publish some submissions if we feel they're not appropriate. We hope you understand.

Don't let your SQL code make you cry!

Use jOOQ, instead of JDBC.

jOOQ generates Java code from your database and lets you build typesafe SQL queries through its fluent API.

Don't let your SQL code make you cry! Get back in control of your SQL with jOOQ.