5 Replies Latest reply: Apr 1, 2014 10:51 AM by Jani Rautiainen-Oracle RSS

    JNDI connectivity from java servlet to database cloud

    43bdb272-cf53-4f63-bb03-02cee2df5adb

      I am using this code to access my data on database cloud

       

      Context ctx = null;

             

              Hashtable ht = new Hashtable();

             

              ht.put(Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory");

            //  ht.put(Context.PROVIDER_URL,"sftp.us1.cloud.oracle.com:22");

             

              Connection conn = null;

             

              Statement stmt = null;

             

              ResultSet rs = null;

             

              try {

                 

                  ctx = new InitialContext(ht);

                 

                  javax.sql.DataSource ds = (javax.sql.DataSource) ctx.lookup("javatrial5196db"); //this is my database instance name

                  out.print(ds.toString());

                 

                  conn = ds.getConnection();

                 

                  stmt = conn.createStatement();

                 

                  rs = stmt.executeQuery("select * from test");

                 

      //            while (rs.next()) {

      //                out.println(rs.getString(0) + "   " + rs.getString(1));

      //            }

                 

                  stmt.close();

                 

                  stmt = null;

                 

                  conn.close();

                 

                  conn = null;

                 

              } catch (Exception e) {

                 

                  throw new RuntimeException(e);

                 

              } finally {

                 

                  try {

                     

                      ctx.close();

                     

                      if (rs != null) {

                          rs.close();

                      }

                     

                      if (stmt != null) {

                          stmt.close();

                      }

                     

                      if (conn != null) {

                          conn.close();

                      }

                     

                  } catch (Exception e) {

                     

                      throw new RuntimeException(e);

                     

                  }

       

       

      And i get HTTP 500 error internal error when i run it . What should i do ? i am not able to understand what will be my databse name , i never created one (i only created tables on database cloud) , Some suggested to use only "database" as datasource name but it aalso does not work? please help