Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 5 of 5

Thread: JDBC CONNECTION ERROR in eclipse

  1. #1
    Junior Member
    Join Date
    Jun 2014
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default JDBC CONNECTION ERROR in eclipse

    I can't get my post to be excepted.


  2. #2
    Junior Member
    Join Date
    Jun 2014
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default JDBC CONNECTION ERROR in eclipse

    I am a Java beginner.

    I am trying to connect to our oracle database through Eclipse. I have the following package.

    We are at Oracle 11g Java 1.7 I have the ojdbc7.jar driver downloaded and placed in the classpath.

    Yet I keep getting the error below:

    No sure if this is an Eclipse problem, my code, or both.

     //connection code
    package testConnect;
    import java.sql.*;
    import oracle.jdbc.OracleDriver;
     
    public class JdbcThinTnsNamesTest {
        public JdbcThinTnsNamesTest() {
            System.setProperty("oracle.net.tns_admin",
                    "$TNS_ADMIN");
        }
     
        public static Connection getConnection() throws SQLException {
            String username = "user";
            String password = "password";
            String thinConn = "jdbc:oracle:thin:@//NCPP";
            DriverManager.registerDriver(new OracleDriver());
            Connection conn = DriverManager.getConnection(thinConn, username,
                    password);
            conn.setAutoCommit(false);
            return conn;
        }
        //
        public void run() throws SQLException {
            Connection conn = getConnection();
            System.out.println("Auto Commit = " + conn.getAutoCommit());
            conn.close();
        }
     
        public static void main(String[] args) {
            JdbcThinTnsNamesTest test = new JdbcThinTnsNamesTest();
            try {
                test.run();
                System.out.println("all done..");
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
     
    }
     
    package oracle.jdbc;
     
    import java.sql.Connection;
    import java.sql.Driver;
    import java.sql.DriverPropertyInfo;
    import java.sql.SQLException;
    import java.sql.SQLFeatureNotSupportedException;
    import java.util.Properties;
    import java.util.logging.Logger;
     
    public class OracleDriver implements Driver {
     
    	@Override
    	public Connection connect(String url, Properties info) throws SQLException {
    		// TODO Auto-generated method stub
    		return null;
    	}
     
    	@Override
    	public boolean acceptsURL(String url) throws SQLException {
    		// TODO Auto-generated method stub
    		return false;
    	}
     
    	@Override
    	public DriverPropertyInfo[] getPropertyInfo(String url, Properties info)
    			throws SQLException {
    		// TODO Auto-generated method stub
    		return null;
    	}
     
    	@Override
    	public int getMajorVersion() {
    		// TODO Auto-generated method stub
    		return 0;
    	}
     
    	@Override
    	public int getMinorVersion() {
    		// TODO Auto-generated method stub
    		return 0;
    	}
     
    	@Override
    	public boolean jdbcCompliant() {
    		// TODO Auto-generated method stub
    		return false;
    	}
     
    	@Override
    	public Logger getParentLogger() throws SQLFeatureNotSupportedException {
    		// TODO Auto-generated method stub
    		return null;
    	}
     
    }

    java.sql.SQLException: No suitable driver found for jdbcracle:thin:@//NCPP
    at java.sql.DriverManager.getConnection(DriverManager .java:596)
    at java.sql.DriverManager.getConnection(DriverManager .java:215)
    at testConnect.JdbcThinTnsNamesTest.getConnection(Jdb cThinTnsNamesTest.java:17)
    at testConnect.JdbcThinTnsNamesTest.run(JdbcThinTnsNa mesTest.java:24)
    at testConnect.JdbcThinTnsNamesTest.main(JdbcThinTnsN amesTest.java:32)

  3. #3
    Member Ada Lovelace's Avatar
    Join Date
    May 2014
    Location
    South England UK
    Posts
    192
    My Mood
    Sleepy
    Thanks
    17
    Thanked 32 Times in 28 Posts

    Default Re: JDBC CONNECTION ERROR in eclipse

    import oracle.jdbc.OracleDriver;
    Looks like it's referring to this line. Have you checked if the library is within
    the Eclipse build project files? If the driver is missing perhaps it's a botch install?
    Try downloading the library again and linking it with your project.

    Wishes Ada xx
    If to Err is human - then programmers are most human of us all.
    "The Analytical Engine offers a new, a vast, and a powerful language . . .
    for the purposes of mankind
    ."
    Augusta Ada Byron, Lady Lovelace (1851)

  4. #4
    Super Moderator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,225
    Thanks
    176
    Thanked 817 Times in 760 Posts
    Blog Entries
    5

    Default Re: JDBC CONNECTION ERROR in eclipse

    Try to explicitly load the database driver prior to trying to make the connection
    Class.forName("oracle.jdbc.driver.OracleDriver");

  5. #5
    Junior Member
    Join Date
    Jun 2014
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: JDBC CONNECTION ERROR in eclipse

    Thanks Ada,

    Followed your suggestion. Ran program again and get the following errror.

    Error: Could not find or load main class oracle.sql.CharacterSetFactory

Similar Threads

  1. connection of jdbc with mysql
    By bhagyashree devji in forum What's Wrong With My Code?
    Replies: 2
    Last Post: January 21st, 2013, 08:46 AM
  2. JDBC Too Many Connection Error
    By sajithgsm in forum JDBC & Databases
    Replies: 1
    Last Post: February 22nd, 2012, 04:08 AM
  3. jdbc connection problem
    By sny in forum JDBC & Databases
    Replies: 11
    Last Post: January 6th, 2011, 03:39 AM
  4. JDBC connection error
    By nrao in forum What's Wrong With My Code?
    Replies: 7
    Last Post: November 11th, 2010, 11:43 AM
  5. jdbc connection with phpmyadmin
    By anand_fevi in forum JDBC & Databases
    Replies: 1
    Last Post: May 13th, 2010, 02:26 AM

Tags for this Thread