943,619 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Unsolved
  • Views: 13649
  • Java RSS
Apr 1st, 2006
0

illegal start of type -- NetBeans

Expand Post »
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:odbcriver={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() {
}

}
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
dgrblr is offline Offline
7 posts
since Mar 2006
Apr 1st, 2006
0

Re: illegal start of type -- NetBeans

Looks like you might have one to many curly braces.
Reputation Points: 113
Solved Threads: 19
Postaholic
server_crash is offline Offline
2,108 posts
since Jun 2004
Apr 1st, 2006
0

Re: illegal start of type -- NetBeans

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:odbcriver={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;
}

}
Reputation Points: 10
Solved Threads: 0
Newbie Poster
dgrblr is offline Offline
7 posts
since Mar 2006

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Java Forum Timeline: clarify my doubt
Next Thread in Java Forum Timeline: Source Code that don't work?





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC