?
Solved

how to make sure that my connection to database works?

Posted on 2007-04-09
1
Medium Priority
?
245 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 2000 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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

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…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
This video shows how to copy an entire tablespace from one database to another database using Transportable Tablespace functionality.
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
Suggested Courses
Course of the Month9 days, 4 hours left to enroll

765 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