Results 1 to 6 of 6
  1. #1
    supersons is offline Member
    Join Date
    Dec 2012
    Posts
    3
    Rep Power
    0

    Cool problems connecting to jdbc:odbc

    Hi,

    when trying to connect to my MS Access database my java app is now displaying the below before eventually connecting:

    problems connecting to jdbc:odbc:kirky (name of my database)
    problems connecting to jdbc:odbc:kirky (name of my database)
    problems connecting to jdbc:odbc:kirky (name of my database)
    problems connecting to jdbc:odbc:kirky (name of my database)
    problems connecting to jdbc:odbc:kirky (name of my database)

    I have checked the DSN in the OBDC part of control panel on my Windows XP home machine and everything looks to be setup correctly. I have tested the database connection on my windows 7 machine in XP mode and I do not get the above. All seems abit inconsistent. Please can you advise code is below:

    Java Code:
    import java.sql.*;
    
    public class Database
    {
        public Statement m_Stmt;
        public Connection m_Con;
        
        public Database()
        {
            m_Stmt = null;
            m_Con = null;
        }
    
        public void Connection()
        {
            String odbcSourceName = "jdbc:odbc:kirky";
            String s1 = "";
            String s2 = "";       
            try
            {
                Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
                //System.out.println("First Part Worked");
            }
            catch(Exception exception)
            {
                System.out.println("Failed to load JDBC/ODBC driver.");
                return;
            }
    /*
     			// change this to whatever your DSN is
     			String dataSourceName = "kirky";
     			String dbURL = "jdbc:odbc:" + dataSourceName;
     			try 
     			{ 
    				Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    				Connection con = DriverManager.getConnection(dbURL, "",""); 
     			}
     			catch (Exception err) 
     			{
    				System.out.println( "Error: " + err );
     			}
    */
    		try
            {
                m_Con = DriverManager.getConnection(odbcSourceName, s1, s2);
                m_Stmt = m_Con.createStatement();
            }
            catch(Exception exception1)
            {
                System.out.println("problems connecting to " + odbcSourceName);
            }
    
    
    
        }
    
        
        public void ExecuteUpdate(String s)
        {
            try 
            {
                m_Stmt.executeUpdate(s);
                System.out.println("round 1");
            } 
            catch (SQLException e) 
            {
                System.out.println("problems with update SQL : " + e.getMessage());
            }
        }
    
        public ResultSet Execute(String s)
        {
            try {
    		return m_Stmt.executeQuery(s);
            } catch (SQLException e) {
                System.out.println("problems with SQL : " + e.getMessage());
            }
            return null;
        }
    
        public void ExecuteNoResult(String s)
        {
            try
            {
                m_Stmt.execute(s);
            }
            catch(Exception exception)
            {
                System.out.println("problems with SQL : " + exception.getMessage());
            }
        }
    
        public void Close()
        {
            try
            {
                m_Con.close();
            }
            catch(Exception exception) { }
        }
    
        public static void main(String args[])
        {
            try
            {
                Database database = new Database();
                database.Connection();
                ResultSet resultset = database.Execute("Select * from Area");
                if(resultset != null)
                    for(; resultset.next(); System.out.println(resultset.getString("AreaName")));
                database.Close();
            }
            catch(Exception exception)
            {
                System.out.println(exception.toString());
    			exception.printStackTrace();
            }
        }
    }
    Last edited by supersons; 12-10-2012 at 06:44 PM.

  2. #2
    quad64bit's Avatar
    quad64bit is offline Moderator
    Join Date
    Jul 2009
    Location
    VA
    Posts
    1,323
    Rep Power
    7

    Default Re: problems connecting to jdbc:odbc

    Hello and welcome! Please use [code][/code] tags when posting code so we can easily read it!

    Forum Rules
    Guide For New Members
    BB Code List - Java Programming Forum

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

    Default Re: problems connecting to jdbc:odbc

    And replace those Sysout statements in your catch blocks with exception.printStackTrace().
    That will tell you exactly what problem you are getting, and exactly where it is occurring.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  4. #4
    supersons is offline Member
    Join Date
    Dec 2012
    Posts
    3
    Rep Power
    0

    Default Re: problems connecting to jdbc:odbc

    Ok will give it ago.

    Thanks

  5. #5
    supersons is offline Member
    Join Date
    Dec 2012
    Posts
    3
    Rep Power
    0

    Default Re: problems connecting to jdbc:odbc

    Hi,

    output below:

    Java Code:
    java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver] Too many client
      tasks.
             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)
             at Database.Connection(Database.java:46)
             at MenuData.populateVector(MenuData.java:25)
             at Start.setupSpecialMenu(Start.java:97)
             at Start.main(Start.java:128)
    java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver] Too many client
      tasks.
             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)
             at Database.Connection(Database.java:46)
             at MenuData.populateVector(MenuData.java:25)
             at Start.setupSpecialMenu(Start.java:97)
             at Start.main(Start.java:128)
    java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver] Too many client
      tasks.
             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)
             at Database.Connection(Database.java:46)
             at Start.setupSpecialMenu(Start.java:80)
             at Start.main(Start.java:128)
    java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver] Too many client
      tasks.
             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)
             at Database.Connection(Database.java:46)
             at MenuData.populateVector(MenuData.java:25)
             at Start.setupSpecialMenu(Start.java:97)
             at Start.main(Start.java:128)
    java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver] Too many client
      tasks.
             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)
             at Database.Connection(Database.java:46)
             at MenuData.populateVector(MenuData.java:25)
             at Start.setupSpecialMenu(Start.java:97)
             at Start.main(Start.java:128)

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

    Default Re: problems connecting to jdbc:odbc

    That's an error thrown by the ODBC driver (or Access itself, not sure), so not really a Java question.
    Going solely by the message it looks like your connections are not being closed properly.

    You haven't shown the code where you use this stuff.

    For connections you want something along the lines of:
    Java Code:
    Connection con = null;
    try {
       con = getConnection();
       Statement st = null
       try {
          st = con.createStatement();
          ResultSet rs = null;
          try {
             rs = st.execute();
             try {
                while (rs.next()) { do stuff}
             } finally {
                rs.close();
             }
          } finally {
             st.close();
          }
       } finally {
          con.close();
       }
    } catch (SQLException ex) {
       ex.printStackTrace();
    }
    In other words, don't hold onto the Connection for too long. The exception to this is if it's a single threaded app, or you can ensure only one thread will access the connection at any one time. That would only really apply to a desktop app, and even then you need to ensure your GUI works such that multiple events do not fire off multiple queries at the same time.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

Similar Threads

  1. jdbc odbc problem
    By shancay08 in forum NetBeans
    Replies: 3
    Last Post: 09-11-2012, 06:08 PM
  2. JDBC ODBC SQLException
    By JohnPringle83 in forum JDBC
    Replies: 6
    Last Post: 05-30-2011, 08:07 AM
  3. jdbc-odbc cannot connect
    By ArneBassez in forum JDBC
    Replies: 4
    Last Post: 12-08-2010, 05:26 AM
  4. Help me this error in JDBC-ODBC connection
    By lordelf in forum Java Servlet
    Replies: 3
    Last Post: 04-04-2009, 08:37 AM
  5. Using JDBC-ODBC bridge
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 02-06-2008, 09:21 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
  •