1 Reply Latest reply on Jan 3, 2020 8:00 PM by David Salter

    error when connection to database

    Tony007

      hi am having this error when trying to connect to database

       

      Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0

      at oracle.jdbc.driver.JavaToJavaConverter.main(JavaToJavaConverter.java:3562)

       

       

      this my code

      import java.sql.Connection;
      import java.sql.DriverManager;
      
      
      import javax.sql.DataSource;
      
      
      import org.springframework.beans.factory.annotation.Autowired;
      import org.springframework.boot.SpringApplication;
      import org.springframework.boot.autoconfigure.SpringBootApplication;
      
      
      
      @SpringBootApplication
      public class DBConnection {
      
      //@Autowired
          //DataSource dataSource;
      
      
      
      public static void  main(String[] args) {
      
      //SpringApplication.run(DBConnection.class, args);
      
      SpringApplication.run(DBConnection .class, args);
      
      String jdbcUrl = "jdbc:oracle:thin:@hostname:1521/dbname.world";
      String user = "username";
      String pass = "pswd";
      try {
      System.out.println("connected " + jdbcUrl);
      
      Connection myconn = DriverManager.getConnection(jdbcUrl,user,pass);
      
      System.out.println("Connection succeful");
      }
      catch(Exception exec ) {
      exec.printStackTrace();
      }
      }
      
      
        /*public void run(String... args) throws Exception {
      
      
              System.out.println("DATASOURCE = " + dataSource);
      
      

       

       

      }