using jdbc to connect to db2

Discussion in 'Java' started by r_stringer66@yahoo.com, Jul 26, 2005.

  1. Guest

    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
     
    , Jul 26, 2005
    #1
    1. Advertising

  2. jeak110 Guest

    /*## 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)

    пиÑал(а):
    > 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, Jul 27, 2005
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Kate Perry

    connect to db2 database using dbi?

    Kate Perry, Jul 10, 2003, in forum: Perl
    Replies:
    0
    Views:
    3,250
    Kate Perry
    Jul 10, 2003
  2. Cool Calm Serene

    jdbc connections to db2

    Cool Calm Serene, Sep 4, 2003, in forum: Java
    Replies:
    0
    Views:
    551
    Cool Calm Serene
    Sep 4, 2003
  3. Replies:
    0
    Views:
    7,627
  4. Dinesh
    Replies:
    0
    Views:
    169
    Dinesh
    Apr 3, 2006
  5. Replies:
    0
    Views:
    186
Loading...

Share This Page