Hi,

I have an problem with connecting Oracle 10g express edition with java.

I am accessing my Oracle 10g with the following URL:
localhost:8080/apex

I am using the following code:

try
{
  Class.forName("oracle.jdbc.driver.OracleDriver");

  Connection con = DriverManager.getConnection("jdbc:oracle:thin:@localhost:8080:xe","hr","hr");
  System.out.println("Connected Successfully To Oracle");
  con.close();
}
catch(Exception ex)
{
  ex.printStackTrace();
}

Is the code I wrote correct????

If not please suggest me the correct code.

Thanks in advance.....

Recommended Answers

Would you mind to share it? You may possibly help somebody in the future with same/similar issue....

Jump to Post

All 3 Replies

I have got the solution and now its working fine......

Would you mind to share it? You may possibly help somebody in the future with same/similar issue....

Would you mind to share it? You may possibly help somebody in the future with same/similar issue....

Why Not!!
Here is my code which is working fine.

I am accessing tomcat with: localhost/8084
and oracle 10g with:localhost:8080/apex

Following is the java code:

try
        {
            // Load the JDBC driver
            String driverName = "oracle.jdbc.OracleDriver";
            Class.forName(driverName);

            // Create a connection to the database
            String serverName = "127.0.0.1";
            String portNumber = "1521";
            String sid = "XE";
            String url = "jdbc:oracle:thin:@" + serverName + ":" + portNumber + ":" + sid;
            System.out.println(url);
            String username = "xxxxxxx";
            String password = "xxxxxxx";
            try{
            connection = DriverManager.getConnection(url, username, password);
            }
            catch(Exception e)
            {
                System.out.println("Connection Error: " + e);
            }
            String sql = "select * from test" ;
            Statement stmt = connection.createStatement();
            try
            {
                ResultSet rs = stmt.executeQuery(sql);

                while (rs.next())
                {
                    System.out.println("results: " + rs.getString("id"));
                    System.out.println("results: " + rs.getString("name"));
                    System.out.println("results: " + rs.getString("password"));
                }
            }
            catch(Exception e)
            {
                System.out.println("result set Error: " + e);
            }
            connection.close();
            //System.out.println("Error Class Found");
        }
        catch (ClassNotFoundException e)
        {
            System.out.println("Error Class Not Found"+e);
        }
       catch (SQLException e)
       {
            System.out.println("SQL Error"+e);
       }
commented: Thank you for sharing +16
Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.21 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.