Announcement Announcement Module
Collapse
No announcement yet.
Oracle Jdbc invalid url problem Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Oracle Jdbc invalid url problem

    Hallo,
    I have a problem similar to the one described in this thread but I couldn't fix it so far.
    http://forum.springframework.org/showthread.php?t=10870

    I am running an application using Spring but no Hibernate on Tomcat 5. Using MySQL is no problem but trying to connect to an Oracle 10g database is impossible. I am using these connection details for my DataSource:
    Code:
        	<property name="username"><value>user</value></property>
        	<property name="password"><value>pw</value></property>
        	<property name="url"><value>jdbc:oracle:thin:@servername:1521:teacup</value></property>
        	<property name="driver"><value>oracle.jdbc.driver.OracleDriver</value></property>
    Running it on a desktop with W2k the log file shows an Invalid Jdbc Url error after displaying that spring obviously translated the url into
    jdbc:oracle://servername:1521/teacup. Connecting to the database from the commandline is no problem using simple jdbc code.
    When I try to run either the application or the little test program on the WinXP machine it says 'Io exception: The Network Adapter could not establish the connection'.
    What is the problem? Is it ok that Spring changes the database url? If not, how can I prevent this? It's fine with MySQL but the application has to run with Oracle so I need to sort that out. Any ideas?
    Thanks,
    Joachim
    Last edited by robyn; May 14th, 2006, 12:08 PM.

  • #2
    could you show how you access this datasource from Spring / Hibernate?

    Comment


    • #3
      Hi,
      I do nothing else than using code like this that I took from the Spring Reference Guide. I have 9 classes that act as mediators between the controllers and the database. Each of them has a few methods that contain this piece of code.
      Code:
      ...
      JdbcTemplate jt = new JdbcTemplate&#40;dataSource&#41;;
      String query = "...";
      List l = jt.queryForList&#40;query&#41;;
      ...
      I don't use Hibernate since the application isn't that big and I don't have time to figure out how it goes. Is there any kind of configuration that I missed to use?
      Cheers
      Joachim

      Comment


      • #4
        I connect to Oracle every day using the Spring configuration of the datasource and the thin drivers. I don't think Spring is your problem. Have you tryed configuring the datasource programatically thus ruling out Spring as the culprit?

        I my experience, if I see an error like that, it's an Oracle networking problem. I never trust their error messages either, invariably they have no relation to the actual problem.

        Comment


        • #5
          This is my data source, it is used as an attribute by every bean that has to talk to the database.
          It is still not clear to me why a simple piece of 'classic'* jdbc code connects and the fancy spring does not.

          Code:
          package cms.data.db.oracle;
          
          import java.sql.Connection;
          import java.sql.DriverManager;
          
          import java.sql.SQLException;
          
          import javax.sql.DataSource;
          
          import org.apache.commons.logging.Log;
          import org.apache.commons.logging.LogFactory;
          
          /**
           *
           * @author  jf
           */
          public class OracleDataSource implements DataSource &#123;
              
              private final Log logger = LogFactory.getLog&#40;this.getClass&#40;&#41;&#41;;
              
              private String url = null;
              private String driver = null;
          
              private String username = null;
              private String password = null;
              
              public void setUsername&#40;String username&#41;&#123;
                  this.username = username;
              &#125;
              
              public String getUsername&#40;&#41;&#123;
                  return this.username;
              &#125;
              
              public String getPassword&#40;&#41;&#123;
                  return this.password;
              &#125;
              
              public void setPassword&#40;String password&#41;&#123;
                  this.password = password;
              &#125;
              
              public void setUrl&#40;String url&#41;&#123;
                  this.url = url;
              &#125;
              
              public String getUrl&#40;&#41;&#123;
                  return this.url;
              &#125;
              
              public void setDriver&#40;String driver&#41;&#123;
                  this.driver = driver;
              &#125;
              
              public String getDriver&#40;&#41;&#123;
                  return this.driver;
              &#125;
              
              /** Creates a new instance of OracleDataSource */
              public OracleDataSource&#40;&#41; &#123;
              &#125;
              
              public Connection getConnection&#40;&#41; throws SQLException &#123;
                  Connection result = null;
                  try &#123;
                  Class.forName&#40;getDriver&#40;&#41;&#41;;    
                  &#125;
                  catch &#40;ClassNotFoundException cnfe&#41;&#123;
                      logger.error&#40;cnfe&#41;;
                  &#125;                
                  result = DriverManager.getConnection&#40;getUrl&#40;&#41;, getUsername&#40;&#41;, getPassword&#40;&#41;&#41;;
                  return result;
              &#125;
              
              public Connection getConnection&#40;String username, String password&#41; throws SQLException &#123;
                  this.username = username;
                  this.password = password;
                          
                  return getConnection&#40;&#41;;        
              &#125;
              
              public java.io.PrintWriter getLogWriter&#40;&#41; throws java.sql.SQLException &#123;
                  throw new RuntimeException&#40;"not implemented"&#41;;
              &#125;
              
              public int getLoginTimeout&#40;&#41; throws java.sql.SQLException &#123;
                  throw new RuntimeException&#40;"not implemented"&#41;;
              &#125;
              
              public void setLogWriter&#40;java.io.PrintWriter out&#41; throws java.sql.SQLException &#123;
                  throw new RuntimeException&#40;"not implemented"&#41;;
              &#125;
              
              public void setLoginTimeout&#40;int seconds&#41; throws java.sql.SQLException &#123;
                  throw new RuntimeException&#40;"not implemented"&#41;;
              &#125;
              
          &#125;
          Cheers
          Joachim


          * classic =
          Code:
          ...
          url = System.getProperty&#40;"DB_URL"&#41;;
          db_driver = System.getProperty&#40;"DB_DRIVER"&#41;;
          Class.forName&#40;db_driver&#41;; 
          conn = DriverManager.getConnection&#40;url,username,password&#41;;
          ...

          Comment


          • #6
            Spring is not going to change the URL on you. If you are passing in the URL as a string to a string property, it's going to stay exactly as you specified it. You could log from your DataSource class to verify this.

            However, I'm confused as to why you are even rolling your own DataSource implementation. What you have right now looks pretty similar to DriverManagerDataSource, which comes with Spring, but I would personally, even for tests, just use DBCP from apache, which is trivial to set up and as a bean, and you'll get pooling, which your DataSource and DriverManagerDataSource don't offer.

            Comment

            Working...
            X