Results 1 to 6 of 6

Thread: Oracle Jdbc invalid url problem

Hybrid View

  1. #1
    Join Date
    Oct 2004
    Posts
    3

    Default 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 at 11:08 AM.

  2. #2
    Join Date
    Aug 2004
    Location
    Montréal, Canada
    Posts
    845

    Default

    could you show how you access this datasource from Spring / Hibernate?
    Omar Irbouh

    Spring Modules Team
    http://irbouh.blogspot.com/

  3. #3
    Join Date
    Oct 2004
    Posts
    3

    Default

    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

  4. #4
    Join Date
    Aug 2004
    Location
    San Francisco
    Posts
    423

    Default

    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.

  5. #5
    Join Date
    Oct 2004
    Posts
    3

    Default

    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;;
    ...

  6. #6
    Join Date
    Aug 2004
    Location
    Toronto, Canada
    Posts
    736

    Default

    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.
    Colin Sampaleanu
    SpringSource - http://www.springsource.com

Similar Threads

  1. Replies: 4
    Last Post: May 11th, 2012, 08:34 AM
  2. Replies: 6
    Last Post: Oct 13th, 2009, 09:08 AM
  3. Oracle, Spring - JDBC exception
    By jakim8915 in forum Data
    Replies: 5
    Last Post: Aug 7th, 2006, 09:20 AM
  4. Problem with JDBC DAO and MySQL
    By johnny2005 in forum Data
    Replies: 7
    Last Post: Jun 21st, 2005, 04:17 PM
  5. Spring in eclipse RCP - JDBC Problem
    By ryanhowai in forum Architecture
    Replies: 10
    Last Post: Dec 31st, 2004, 03:29 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •