user1068295
user1068295

Reputation: 11

Connecting DB2 Express-C in java using Eclipse Indigo

I am pretty new to JDBC and I am trying to write a simple application to connect to a DB2 database residing on the same machine.

I am looking for a code snippet and the necessary 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 someone could point me to the right direction in this regards.

Upvotes: 1

Views: 2333

Answers (1)

aleroot
aleroot

Reputation: 72676

You need DB2 jdbc driver, then you can write something like this :

// load the DB2 Driver
Class.forName("COM.ibm.db2.jdbc.app.DB2Driver");

// establish a connection to DB2
Connection db2Conn = DriverManager.getConnection("jdbc:db2:test","user","pass");

Statement st = db2Conn.createStatement();
String myQuery = "SELECT * FROM TEST"; 

// execute the query
ResultSet resultSet = st.executeQuery(myQuery); 

Upvotes: 1

Related Questions