Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Java
  4. Error connecting Oracle on localhost: Could not get JDBC Connection ?

Error connecting Oracle on localhost: Could not get JDBC Connection ?

Scheduled Pinned Locked Moved Java
databasequestionoraclehelp
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    taibc
    wrote on last edited by
    #1

    Hi everyone, I am trying to connect Oracle database from my web application using Eclipse. But I got the error:org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; I used below code:

    public static void initDB(){
    try {
    BasicDataSource ds = new BasicDataSource();
    ds.setDriverClassName("oracle.jdbc.driver.OracleDriver");
    ds.setUrl("jdbc:oracle:thin:@localhost:1521:xe");
    ds.setUsername("mybank");
    ds.setPassword("123456");

    		jdbcTemplate  = new JdbcTemplate(ds); // throw exceptiong after this line
    		isConnected = true;
    		initSystemPros();
    	} catch (Exception e) {
    		System.err.println("Cannot connect to DataBase");
    		isConnected = false;
    	}
    }
    

    I tried to use SQL Developer to create a connection using above settings and successful. Do you know what is wrong ? Thanks and regards, Tai

    J 2 Replies Last reply
    0
    • T taibc

      Hi everyone, I am trying to connect Oracle database from my web application using Eclipse. But I got the error:org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; I used below code:

      public static void initDB(){
      try {
      BasicDataSource ds = new BasicDataSource();
      ds.setDriverClassName("oracle.jdbc.driver.OracleDriver");
      ds.setUrl("jdbc:oracle:thin:@localhost:1521:xe");
      ds.setUsername("mybank");
      ds.setPassword("123456");

      		jdbcTemplate  = new JdbcTemplate(ds); // throw exceptiong after this line
      		isConnected = true;
      		initSystemPros();
      	} catch (Exception e) {
      		System.err.println("Cannot connect to DataBase");
      		isConnected = false;
      	}
      }
      

      I tried to use SQL Developer to create a connection using above settings and successful. Do you know what is wrong ? Thanks and regards, Tai

      J Offline
      J Offline
      jorgesys
      wrote on last edited by
      #2

      What is the code inside the method: initSystemPros(); Are you sure 1521 is your port?

      1 Reply Last reply
      0
      • T taibc

        Hi everyone, I am trying to connect Oracle database from my web application using Eclipse. But I got the error:org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; I used below code:

        public static void initDB(){
        try {
        BasicDataSource ds = new BasicDataSource();
        ds.setDriverClassName("oracle.jdbc.driver.OracleDriver");
        ds.setUrl("jdbc:oracle:thin:@localhost:1521:xe");
        ds.setUsername("mybank");
        ds.setPassword("123456");

        		jdbcTemplate  = new JdbcTemplate(ds); // throw exceptiong after this line
        		isConnected = true;
        		initSystemPros();
        	} catch (Exception e) {
        		System.err.println("Cannot connect to DataBase");
        		isConnected = false;
        	}
        }
        

        I tried to use SQL Developer to create a connection using above settings and successful. Do you know what is wrong ? Thanks and regards, Tai

        J Offline
        J Offline
        jorgesys
        wrote on last edited by
        #3

        Be sure that `xe` is your `Service Name`. If the connection is successfull but you have this exception `SQLNestedException: Cannot create PoolableConnectionFactory (Io exception: The Network Adapter could not establish the connection) at` " you must have an incompatible version of JDBC, install the correct one: http://www.oracle.com/technetwork/database/enterprise-edition/jdbc-10201-088211.html

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups