Skip to main content

Posts

Showing posts from 2013

Connecting to MySQL with Java

I wanted to go over Database connections with Java, as it is something I've seen come up quite a bit, and it's really quite easy.  My intent is to actually go into detail on what actually happens here, so if all you're interested in is some boiler-plate code to get yourself connected, feel free to stop with the code listed below.  The only things to bear in mind are that I am using Java7 SE syntax for the catch block, and also that this method is tailored for the return of a single line result from the database.  Replace the if with a while loop ( and associated extra code ) if you want to loop through more than a single record The following method is called supplying an SQL statement as a string, i.e.:  SQLSingleQueryDB("SELECT * FROM products LIMIT 1");  The result is returned as a String: private String SQLSingleQueryDB( String query ) { String result = null; try { Class.forName("com.mysql.jdbc.Driver").

Codeigniter vs. Kohana Database access speeds

I was doing some basic profiling for a project in which I needed the fastest raw speed I could get with database queries. I'm a fan of Codeigniter for projects that are suitable for it, but had heard from some that Kohana was faster, so I decided to do a very basic comparison of the two. I was using MAMP for OSX, and created a very small db, with a table that had 3 fields: (id), (first), and (last). The data sample was also very small, only a few records. The basic query I tested was a "SELECT * FROM [table]". There is of course nothing remotely scientific about this. It was just a quick ad dirty, very limited comparison. Take it as such. Versions used: CI2.1.3, Kohana 3.3.0. Codeigniter I really like Codeigniter (CI). But, one thing that is very evident from their own profiling functions, is that CI is a bit of a memory hog! Essentially, the same Controller function running in CI takes approximately 10X more memory than in Kohana! This in itself is not