Results 1 to 2 of 2
  1. #1
    KyleS is offline Member
    Join Date
    Feb 2012
    Location
    Albany New York
    Posts
    4
    Rep Power
    0

    Default Trouble connecting to my database,

    It has been awhile since I had to use the JDBC I used some source code from a college class I took when Sun was still independent. I am trying to access an access 2007 database. I am getting these errors connecting to my database

    Java Code:
    :jdbc:odbc:myDatabase
    	at java.net.URLClassLoader$1.run(Unknown Source)
    	at java.net.URLClassLoader$1.run(Unknown Source)
    	at java.security.AccessController.doPrivileged(Native Method)
    	at java.net.URLClassLoader.findClass(Unknown Source)
    	at java.lang.ClassLoader.loadClass(Unknown Source)
    	at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
    	at java.lang.ClassLoader.loadClass(Unknown Source)
    	at java.lang.Class.forName0(Native Method)
    	at java.lang.Class.forName(Unknown Source)
    	at languageInterperater.databaseConnector.connect(databaseConnector.java:26)
    	at languageInterperater.langInterpMain.starting(langInterpMain.java:65)
    	at languageInterperater.langInterpMain.main(langInterpMain.java:18)
    java.sql.SQLException: [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified
    	at sun.jdbc.odbc.JdbcOdbc.createSQLException(Unknown Source)
    	at sun.jdbc.odbc.JdbcOdbc.standardError(Unknown Source)
    	at sun.jdbc.odbc.JdbcOdbc.SQLDriverConnect(Unknown Source)
    	at sun.jdbc.odbc.JdbcOdbcConnection.initialize(Unknown Source)
    	at sun.jdbc.odbc.JdbcOdbcDriver.connect(Unknown Source)
    	at java.sql.DriverManager.getConnection(Unknown Source)
    	at java.sql.DriverManager.getConnection(Unknown Source)Problem connecting with database
    Database Connection Sucessful
    here are the connect and disconnect methods that are contained in a class called databaseConnector which is referred to from a method in main()

    Java Code:
    protected void connect(String url)
    	{
    		/** Disconnects from database
    		 *  connect()
    		 */
    		System.out.println("Connecting to Database: ");
    		try
    		{
    			Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    		}
    		catch(ClassNotFoundException e)
    		{
    			e.printStackTrace();	
    			System.out.println("Connection failed no java database driver " +
    					"installed or no database at location \n:"  + url);
    		}
    		try
    		{
    			con =DriverManager.getConnection(url, "" ,"");//connects to a database
    		}
    	
    		catch(SQLException ex)
    		{
    			ex.printStackTrace();
    			System.out.println("Problem connecting with database");
    		}
    		
    		System.out.println("Database Connection Sucessful");
    		
    	}
    
    	protected void disconnect()
    	{
    		/** Disconnects from database
    		 *  disconnect()
    		 */
    		System.out.println("Closing connection to database ");
    		try
    		{
    			Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    		}
    		catch(ClassNotFoundException e)
    		{
    			e.printStackTrace();	
    			System.out.println("Operation failed no java database driver installed: ");
    		}
    		try
    		{
    			con.close();
    			System.exit(0);
    		}
    		catch(SQLException ex)
    		{
    			ex.printStackTrace();
    			System.out.println("Problem disconnecting from database");
    			System.out.println("System closing");
    			System.exit(0);
    		}
    		
    	}
    Thank you guys for reading and I appreciate all the help I am sorta stumped as to what is going on

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,044
    Rep Power
    20

    Default Re: Trouble connecting to my database,

    ODBC doesn't recognise the DSN you've given in your URL.
    As the exception says.

Similar Threads

  1. connecting to a database
    By mxb7642 in forum JDBC
    Replies: 5
    Last Post: 09-08-2009, 08:39 AM
  2. connecting to a database
    By kswiss in forum NetBeans
    Replies: 4
    Last Post: 06-25-2009, 06:22 PM
  3. Connecting JSP with database
    By ramachandran in forum JavaServer Pages (JSP) and JSTL
    Replies: 3
    Last Post: 05-13-2009, 06:15 AM
  4. Connecting database from Applet
    By Preethi in forum New To Java
    Replies: 5
    Last Post: 05-21-2008, 08:14 AM
  5. Connecting to a database
    By peiceonly in forum New To Java
    Replies: 2
    Last Post: 04-06-2008, 02:28 PM

Posting Permissions

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