Solved

how to make sure that my connection to database works?

Posted on 2007-04-09
1
243 Views
Last Modified: 2013-12-18
how to make sure that the connection string to my orical data base is correct.
this is my conection code in java

 // Database Connection object
    Connection conn = null;
 
    // Set database URL details.
    String url = "jdbc:oracle:thin:@localhost:1521:orcl";
    try {
     
      // Instantiate the driver class.
      Class.forName("oracle.jdbc.OracleDriver");
     
      // Get the database connection.
      conn = DriverManager.getConnection(url,"system","pass");
    }catch (Exception ex) {
        System.out.println("Exception while getting database connection: "
                           +ex.toString() );

can any one help me to write a select statment to make sure that it goes to my database???

I have this table created:
SQL> CREATE TABLE product_information(PRODUCT_ID           NUMBER(6)      NOT NULL,                                      PRODUCT_NAME         VARCHAR2(50)   NOT NULL,                                      PRODUCT_DESCRIPTION  VARCHAR2(2000) NOT NULL,                                       MIN_PRICE            NUMBER(8,2),                                      LIST_PRICE           NUMBER(8,2));SQL> INSERT INTO product_information VALUES(2400, 'DIMM - 512 MB',         '512 MB DIMM memory. Improved memory upgrade granularity', 380, 448);SQL> INSERT INTO product_information VALUES(2401, 'DIMM - 64MB',        'Memory DIMM: RAM, 64MB (100-MHz Unregistered ECC SDRAM)', 202, 247);SQL> INSERT INTO product_information VALUES(2402, 'EDO - 32MB',        'Memory EDO SIM: RAM, 32 MB (100-MHz Unregistered ECC SDRAM)', 149, 179);
0
Comment
Question by:fm134
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 10

Accepted Solution

by:
Jaax earned 500 total points
ID: 18874745
You could code like this after securing the connection
conn = DriverManager.getConnection(url,"system","pass");
PreparedStatement prep = conn.prepareStatement("select * from product_information");
ResultSet rs = prep.executeQuery();
//Iteratore over the resultset


prep = conn.prepareStatement("select sysdate from dual");
rs = prep.executeQuery();
while(rs.next()){
      System.out.println("Date : "+rs.getDate("sysdate"));

}

OR querying to dual to check DB connection

PreparedStatement prep = conn.prepareStatement("select sysdate from dual");
ResultSet rs = prep.executeQuery();
while(rs.next()){
      System.out.println("Date : "+rs.getDate("sysdate"));

}



0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This post first appeared at Oracleinaction  (http://oracleinaction.com/undo-and-redo-in-oracle/)by Anju Garg (Myself). I  will demonstrate that undo for DML’s is stored both in undo tablespace and online redo logs. Then, we will analyze the reaso…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
This video shows syntax for various backup options while discussing how the different basic backup types work.  It explains how to take full backups, incremental level 0 backups, incremental level 1 backups in both differential and cumulative mode a…

729 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question