I have tried every avenue I can think of, but this forum seems to be the best to supply help. I am creating a class using NetBeans. I have created the following code, but get an error message for the line "public static Connection getConnection (String strFileName, "","") throws Exception. Can anyone tell me why this is an "illegal start of type", and how to correct it?

Thanks again.

import java.sql.*;
/**
 *
 * @author 
 */

    // Static class for connecting to a database
public class connectDatabase        
{
        private static String databaseDriver = "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ=";


//  This is the OFFENDING CODE



         //  Method for getting the connection
     public static Connection getConnection (String strFileName, "","")throws Exception




        {
            Connection databaseConnection;
            try
            {
                Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

                // tests for driver support // Also adds to the driver the database address + stuff
                databaseDriver += strFileName.trim() + ";DriverID=22;READONLY=true)";

                databaseConnection = DriverManager.getConnection(strDriver,"","");

            }
            catch (ClassNotFoundException ex)   //thrown if driver not found
            {
                throw new Exception("\nError loading database Access driver.\nPossible reason is that MS Access does not exist on this computer.");
            }
            catch (SQLException ex)     // Thrown if database can not be found
            {
                throw new Exception("\nError connecting to database \n" +
                        System.getProperty("user.dir") + "\\" + strFileName + "\nPlease make sure the database exists");
            }
            return databaseConnection;
        }
}

    /** Creates a new instance of connectDatabase */
    public connectDatabase() {
    }

}

Looks like you might have one to many curly braces.

I already took out all coding after the second brace beyond the 'return'. Same problem. The actual code now looks like this: Same problem:

import java.sql.*;
/**
 *
 * @author Dave
 */

    // Static class for connecting to a database
public class connectDatabase        
{
        private static String databaseDriver = "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ=";


/// This is the offending code

        //  Method for getting the connection
        public static Connection getConnection (String strFileName, "","") throws Exception
        {



            Connection databaseConnection;
            try
            {
                Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

                // tests for driver support // Also adds to the driver the database address + stuff
                databaseDriver += strFileName.trim() + ";DriverID=22;READONLY=true)";

                databaseConnection = DriverManager.getConnection(strDriver,"","");

            }
            catch (ClassNotFoundException ex)   //thrown if driver not found
            {
                throw new Exception("\nError loading database Access driver.\nPossible reason is that MS Access does not exist on this computer.");
            }
            catch (SQLException ex)     // Thrown if database can not be found
            {
                throw new Exception("\nError connecting to database \n" +
                        System.getProperty("user.dir") + "\\" + strFileName + "\nPlease make sure the database exists");
            }
            return databaseConnection;
        }

   }
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.