Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > using jdbc to connect to db2

Reply
Thread Tools

using jdbc to connect to db2

 
 
r_stringer66@yahoo.com
Guest
Posts: n/a
 
      07-26-2005
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

 
Reply With Quote
 
 
 
 
jeak110
Guest
Posts: n/a
 
      07-27-2005
/*## 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)

http://www.velocityreviews.com/forums/(E-Mail Removed) писал(а):
> 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


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
DB2 under Windows XP - "Missing DB2 Libraries or headers" daf@jaade.com Ruby 0 04-26-2006 03:08 PM
Installing ruby-db2-0.4 for DB2 gives SQLConnect() errors. Dinesh Ruby 0 04-03-2006 04:20 AM
Hibernate 3.1 and db2 connecting using com.ibm.db2.jcc.DB2Driver crawstevenford@gmail.com Java 0 02-19-2006 08:20 PM
Lists: XQuery engines, JDBC and ODBC drivers, OLE DB and .NET providers, DB2 extenders Ken North XML 0 04-17-2004 09:26 PM
jdbc connections to db2 Cool Calm Serene Java 0 09-04-2003 08:50 PM



Advertisments