Wednesday, December 16, 2015

Call Stored Procedure via JdbcTemplate

So I keep having to look somewhere for this information, so I am officially making a blog (so 1990's I know) post about how this goes.  Sure I can go read the Spring JdbcTemplate documentation, but why read through that stuff for a 15 minute task.

1.) Create an Oracle Stored Package/Procedure

CREATE OR REPLACE PACKAGE AddPkg AS

    PROCEDURE addLongs(i_one IN NUMBER, i_two IN NUMBER, o_three OUT NUMBER);

END AddPkg;
/

2.) Create Repository class that wraps the JdbcTemplate logic.

@Repository
public class AdditionRepository {

    private static final String ADD_PKG_PROC = "{call AddPkg.addLongs(?,?,?)}";

    private JdbcTemplate jdbcTemplate;

    public void AdditionRepository(DataSource dataSource) {
        this.jdbcTemplate = new JdbcTemplate(dataSource);
    }

    public Long add(final Long n1, final Long n2) {
        Long retVal = this.jdbcTemplate.execute(new CallableStatementCreator() {

            CallableStatement cs = con.prepareCall(ADD_PKG_PROC);
            cs.setLong(1, n1);
            cs.setLong(2, n2);
            cs.registerOutParameter(3, java.sql.Types.NUMERIC);
            return cs;

        }, new CallableStatementCallback() {
            cs.execute();

            // Note that the position corresponds to the position in the stored procedure
            Long result = cs.getLong(3);
            return result;
        });
    }

    return retVal;
}

While this is a simple example is shows the basics of calling a stored procedure and function using the Spring JdbcTemplate.  I realize there are other ways to perform this operation as well, which I might also document in future, but for know keeping it simple.

So go forth and add numbers....

Monday, May 7, 2012

HTML/CSS Editing

jsFiddle is one of the sites that I have blogged about in the past, there is also another site worth mentioning here and that is CSS Desk.  I found this site to be extremely handy in laying out the base templates of my web pages very quickly.  To be fair, I also want to give a big shout out to HTML Dog which where I go for most of my css references.  What do you use to do HTML/CSS templates?

Wednesday, December 14, 2011

Check Tree

I have created a new jQuery plugin for check boxes in a tree.  I have posted it to jsfiddle.  If you wish to try it out and let me know what you think.  Comments are always welcome.

Thursday, December 1, 2011

Just fiddling' around...

Notespad++, chrome, and chrome debugger.


For quite some time now these tools have been my staple of choice when it comes to writing Javascript.  About a month ago I ran across the website jsfiddle.


jsfiddle is a free online service in which you to create sandbox instances or fiddles.  What it give you is a screen which captures your HTML, css, Javascript, and renders it all in one view.  It supports many of the now-a-day javascript frameworks, such as jQuery, Mootools, etc or no framwork at all for you purists out there.  If this is not enough to make the switch, the site allows you to fork your designs.


Lets say I'm writing a component, and BOOM... I have a new thought, re factoring is in the works, however, I don't want to loose my current design (sentimental reasons).  Using my old method it would be save, copy/paste, rename, reopen.  A lot of wasted time and hopefully, something or one hasn't come to interrupt my new found enlightenment.  jsfiddle is much simpler, just Fork my current design and start a new with my re factoring, saving it in the cloud.


I know it's a stretch but the only caveat that I have found it will not allow you to upload any resources, for what ever reason.


If you haven't already it's worth the few minutes to sign up, and fiddle with some code.

Wednesday, February 2, 2011

Java Memory and Performance

After deploying an application to Tomcat then you receive that nasty line:

Perm Gen....

Well, after a while I started to get really sick of restarting, so I did what every other developer would do ... Google.  So I put together a personal reference of various Java Performance links, that I found to be helpful.  Hopefully, they will be of some help to you as well.

Fight Tomcat's OutOfMemoryError PermGen - by Mark Michaelis

Tuning Garbage Collection Outline
http://www.petefreitag.com/articles/gctuning/

Oracle Java
http://www.oracle.com/technetwork/java/gc-tuning-5-138395.html

Java Blog
http://blogs.sun.com/watt/resource/jvm-options-list.html

Java JVM GC, PermGen, and Memory Options
http://www.brokenbuild.com/blog/2006/08/04/java-jvm-gc-permgen-and-memory-options/

Call Stored Procedure via JdbcTemplate

So I keep having to look somewhere for this information, so I am officially making a blog (so 1990's I know) post about how this goes.  ...