SQLWrapper

Discus your java programs here

SQLWrapper

Postby Duck Man » Thu Jan 24, 2008 3:11 pm

I made this for two of my programs and wished I did for all my sql programs. Its just for mysql right now... but that could be changed pretty easy I think. So for my sql you will need MYSQL Connector/J for this to work. Get it HERE. Feel free to use this and modify it what ever way you want to. The cool thing is it automatically handles reconnecting to a db if get disconnected. It was funny, originally I had it in a loop so it just kept trying to reconnect until it succeeded. But if u fucked up the connect statement then it would just be stuck... lol. So only one try after a fail now.
Attachments
SQLWrapper.java
A Wrapper class for MYSQL
(2.18 KiB) Downloaded 60 times
"To resist is to piss in the wind, anyone who does will end up smelling." - Incubus
User avatar
Duck Man
Captain
 
Posts: 933
Joined: Sun May 22, 2005 10:07 am
Location: Pleasanton, CA

Re: SQLWrapper

Postby Duck Man » Thu Jan 24, 2008 8:08 pm

I thot I should put an example of how to use it. I don't know if this would compile but it should... :-P
Code: Select all
SQLWrapper = new SQLWrapper("jdbc:mysql://cookbookdm.piratehook.com/cookbookdm?user=duckmanis1&password=*******");
rs=sql.select("SELECT name FROM recipes");
rs.first();
System.out.println(rs.getString("name"));

I left out the Exception handling and crap. But this should connect to my cookbook db and get a list of all the names of the recipes and then print out the first name. That is not my password btw :-P.
"To resist is to piss in the wind, anyone who does will end up smelling." - Incubus
User avatar
Duck Man
Captain
 
Posts: 933
Joined: Sun May 22, 2005 10:07 am
Location: Pleasanton, CA


Return to Java

Who is online

Users browsing this forum: No registered users and 1 guest

cron