Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / July 2005

Tip: Looking for answers? Try searching our database.

using jdbc to connect to db2

Thread view: 
r_stringer66@yahoo.com - 26 Jul 2005 21:35 GMT
Hi all,

I am pretty new to JDBC and I am trying to write a simple application
to connect to a db2 database residing on a different machine.

I am looking for a code snippet and the neceesary steps in order to
establish the connection to the database and to send some simple
"SELECT" statements to the database.

I would really appreciate if somone could point me to the right
direction in this regards.

Thanks,
Rob
jeak110 - 27 Jul 2005 06:51 GMT
       /*## loading a connector */
       Connection connection;
       Statement statement;
       ResultSet rs;
       try{
           Class.forName(jdbc_driver_name).newInstance();
       } catch(InstantiationException e){
           logger.info("<error type=\""+e.toString()+"\"
discription=\""+e.getMessage()+"\" />");
           return null;
       } catch(ClassNotFoundException e){
           logger.info("<error type=\""+e.toString()+"\"
discription=\""+e.getMessage()+"\" />");
           return null;
       } catch(IllegalAccessException e){
           logger.info("<error type=\""+e.toString()+"\"
discription=\""+e.getMessage()+"\" />");
           return null;
       }

       /*## connect to database */
       try{
           connection DriverManager.getConnection(dblink_2_ss_database, login2db, pass2db);
       } catch(SQLException e){
           logger.info("<error type=\""+e.toString()+"\"
discription=\""+e.getMessage()+"\" />");
           return "<error type=\""+e.toString()+"\"
discription=\""+e.getMessage()+"\" />";
       }

       /*## connect to database */
       String dkstr;
       try{
           statement = connection.createStatement();
           rs = statement.executeQuery("select q.arendator,q.no_dog,
q.address,q.date_begin, q.date_end, q.position_fc, q.telephone_fc from
arenda.vdog_ar q  where sysdate between q.date_begin and q.date_end");

           rs2xml j = new rs2xml();
           j.setWithoutMDFlag(true);
           dkstr = j.writeXML(rs);
           statement.close();
           connection.close();
       } catch(SQLException e){
           logger.info("<error type=\""+e.toString()+"\"
discription=\""+e.getMessage()+"\" />");
           return "<error type=\""+e.toString()+"\"
discription=\""+e.getMessage()+"\" />";
       }
       return dkstr;

// it's me code!
there is a good book ... John Wiley & Sons - MySQL and Java Developer's
Guide or O'Reilly Java Programming with Oracle JDBC. I dont remember
where I've downloaded it. but I think you can find they here
(ebiku.powernews.ru)

r_stringer66@yahoo.com =BF=D1():
> Hi all,
>
[quoted text clipped - 10 lines]
> Thanks,
> Rob


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.