Results 1 to 12 of 12
  1. #1
    Join Date
    Mar 2007
    Posts
    37

    Question Unanswered: Oracle Connection Problem with Java

    Dear all

    I am trying to connect to Oracle with OCI driver in Java using the following piece of code. The code is error free but still I am not able to create the table. Is the connection string okay? I am using Oracle 10g express edition where the username is the dafault "system", password is "kuetcse" and host string is "xe". Please help me resolving the situation.

    Code:
    import java.io.*;
    import java.sql.*;
    
    public class OraThin {
      public static void main(String[] args) {
        try {
          Connection con=null;
          Class.forName("oracle.jdbc.driver.OracleDriver");
          con=DriverManager.getConnection(
            "jdbc:oracle:oci:@xe", "system","kuetcse");
          Statement s=con.createStatement();
          s.execute("CREATE TABLE test (roll integer)");
          s.close();
          con.close();
       } catch(Exception e){e.printStackTrace();}
     }
    }

  2. #2
    Join Date
    Aug 2003
    Location
    Where the Surf Meets the Turf @Del Mar, CA
    Posts
    7,776
    Provided Answers: 1
    >The code is error free but still I am not able to create the table.
    If it really was "error free", then table would be created.

    Code:
    SQL> CREATE TABLE test (roll integer);
    
    Table created.
    Are you really getting connected to the DB?

    What are the last 10 lines or so from listener.log on DB server system?
    You can lead some folks to knowledge, but you can not make them think.
    The average person thinks he's above average!
    For most folks, they don't know, what they don't know.
    Good judgement comes from experience. Experience comes from bad judgement.

  3. #3
    Join Date
    Mar 2007
    Posts
    37
    Well, when I compile the code in Java, the code runs without error. I am not sure if I am connected to the database yet. I need to know that. Other parameters and the connection string are seeming fine then? I'll check the log later (it's in the lab PC). Thank you.

  4. #4
    Join Date
    Aug 2003
    Location
    Where the Surf Meets the Turf @Del Mar, CA
    Posts
    7,776
    Provided Answers: 1
    By the way, it is considered to be bad practice to CREATE any objects in SYS or SYSTEM schemas.
    You can lead some folks to knowledge, but you can not make them think.
    The average person thinks he's above average!
    For most folks, they don't know, what they don't know.
    Good judgement comes from experience. Experience comes from bad judgement.

  5. #5
    Join Date
    Mar 2007
    Posts
    37
    Quote Originally Posted by anacedent
    it is considered to be bad practice to CREATE any objects in SYS or SYSTEM schemas.
    Can I create a separate schema rather than SYSTEM in Oracle 10g XE?

  6. #6
    Join Date
    Nov 2003
    Posts
    2,935
    Provided Answers: 12
    Quote Originally Posted by rushdishams
    Can I create a separate schema rather than SYSTEM in Oracle 10g XE?
    Just create a new user, give it the privileges to create tables, then connect as that user in your program

    You are aware that your initial post contains the password for your SYSTEM account which is now readable by everyone in the world?

  7. #7
    Join Date
    Mar 2007
    Posts
    37
    Quote Originally Posted by shammat
    Just create a new user, give it the privileges to create tables, then connect as that user in your program

    You are aware that your initial post contains the password for your SYSTEM account which is now readable by everyone in the world?
    Thanks buddy, for the tip...
    you can't do anything with that password as the PC is on a lab where internet connection is forbidden! But still, why can't I get connected with the database? Any tweaks?

  8. #8
    Join Date
    Aug 2003
    Location
    Where the Surf Meets the Turf @Del Mar, CA
    Posts
    7,776
    Provided Answers: 1
    What are the last 10-20 lines or so from listener.log on DB server system?

    open command window on db server system as the owner of Oracle software
    CUT the following commands

    lsnrctl status
    lsnrctl service

    PASTE into command window.
    CUT commands & results from command window
    PASTE results back here
    You can lead some folks to knowledge, but you can not make them think.
    The average person thinks he's above average!
    For most folks, they don't know, what they don't know.
    Good judgement comes from experience. Experience comes from bad judgement.

  9. #9
    Join Date
    Nov 2003
    Posts
    2,935
    Provided Answers: 12
    Quote Originally Posted by rushdishams
    But still, why can't I get connected with the database? Any tweaks?
    Are you sure you are not connected?
    If the connection was not successful then you would get an exception.
    If there was an error during the CREATE table youwould get an exception.

    How do you know the table was not created?
    I assume you are using some kind of query tool to check that.

    In 99% of the cases when things like this happen, you are not connected to the same database from within your program and your query tool.

    Did you try to run a SELECT statement?
    e.g. SELECT 42 FROM dual


    Btw: the driver class you are using is deprecated you should use "oracle.jdbc.driver.OracleDriver" b

  10. #10
    Join Date
    Mar 2007
    Posts
    37
    Anacedent buddy,

    lsnrctl status

    C:\Documents and Settings\Administrator>lsnrctl status

    LSNRCTL for 32-bit Windows: Version 10.2.0.1.0 - Production on 27-JUN-2009 00:24
    :22

    Copyright (c) 1991, 2005, Oracle. All rights reserved.

    Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=EXTPROC_F OR_XE)))
    STATUS of the LISTENER
    ------------------------
    Alias LISTENER
    Version TNSLSNR for 32-bit Windows: Version 10.2.0.1.0 - Produ
    ction
    Start Date 26-JUN-2009 22:03:48
    Uptime 0 days 2 hr. 20 min. 33 sec
    Trace Level off
    Security ON: Local OS Authentication
    SNMP OFF
    Default Service XE
    Listener Parameter File C:\oraclexe\app\oracle\product\10.2.0\server\netwo rk\a
    dmin\listener.ora
    Listener Log File C:\oraclexe\app\oracle\product\10.2.0\server\netwo rk\l
    og\listener.log
    Listening Endpoints Summary...
    (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(PIPENAME=\\.\ pipe\EXTPROC_FOR_XEipc)))
    (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=netlabte acher)(PORT=1521)))
    (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=127.0.0. 1)(PORT=8080))(Presentation=
    HTTP)(Session=RAW))
    Services Summary...
    Service "CLRExtProc" has 1 instance(s).
    Instance "CLRExtProc", status UNKNOWN, has 1 handler(s) for this service...
    Service "PLSExtProc" has 1 instance(s).
    Instance "PLSExtProc", status UNKNOWN, has 1 handler(s) for this service...
    Service "XEXDB" has 1 instance(s).
    Instance "xe", status READY, has 1 handler(s) for this service...
    Service "XE_XPT" has 1 instance(s).
    Instance "xe", status READY, has 1 handler(s) for this service...
    Service "xe" has 1 instance(s).
    Instance "xe", status READY, has 1 handler(s) for this service...
    The command completed successfully
    lsnrctl service

    C:\Documents and Settings\Administrator>lsnrctl service

    LSNRCTL for 32-bit Windows: Version 10.2.0.1.0 - Production on 27-JUN-2009 00:26
    :57

    Copyright (c) 1991, 2005, Oracle. All rights reserved.

    Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=EXTPROC_F OR_XE)))
    Services Summary...
    Service "CLRExtProc" has 1 instance(s).
    Instance "CLRExtProc", status UNKNOWN, has 1 handler(s) for this service...
    Handler(s):
    "DEDICATED" established:0 refused:0
    LOCAL SERVER
    Service "PLSExtProc" has 1 instance(s).
    Instance "PLSExtProc", status UNKNOWN, has 1 handler(s) for this service...
    Handler(s):
    "DEDICATED" established:0 refused:0
    LOCAL SERVER
    Service "XEXDB" has 1 instance(s).
    Instance "xe", status READY, has 1 handler(s) for this service...
    Handler(s):
    "D000" established:2 refused:0 current:2 max:1002 state:ready
    DISPATCHER <machine: NETLABTEACHER, pid: 1016>
    (ADDRESS=(PROTOCOL=tcp)(HOST=netlabteacher)(PORT=1 028))
    Service "XE_XPT" has 1 instance(s).
    Instance "xe", status READY, has 1 handler(s) for this service...
    Handler(s):
    "DEDICATED" established:0 refused:0 state:ready
    LOCAL SERVER
    Service "xe" has 1 instance(s).
    Instance "xe", status READY, has 1 handler(s) for this service...
    Handler(s):
    "DEDICATED" established:0 refused:0 state:ready
    LOCAL SERVER
    The command completed successfully

  11. #11
    Join Date
    Mar 2007
    Posts
    37
    Quote Originally Posted by shammat
    Are you sure you are not connected?
    If the connection was not successful then you would get an exception.
    If there was an error during the CREATE table youwould get an exception.

    Did you try to run a SELECT statement?
    e.g. SELECT 42 FROM dual

    Btw: the driver class you are using is deprecated you should use "oracle.jdbc.driver.OracleDriver" b
    No exception yet.

    Yes, tried that one, but no output.

    "oracle.jdbc.driver.OracleDriver" - did not get this point, it's the same driver class i am using in the code...

  12. #12
    Join Date
    Nov 2003
    Posts
    2,935
    Provided Answers: 12
    Quote Originally Posted by rushdishams
    "oracle.jdbc.driver.OracleDriver" - did not get this point, it's the same driver class i am using in the code...
    Sorry, copy and paste error.
    The class that should be used is "oracle.jdbc.OracleDriver"

    No exception yet.
    Which pretty much means that the connection is working (unless you showed us the wrong code and are actually swallowing the exception).

    Wich tool are you using to verify that the table was not created?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •