| | |
illegal start of type -- NetBeans
![]() |
•
•
Join Date: Mar 2006
Posts: 7
Reputation:
Solved Threads: 0
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
river={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() {
}
}
Thanks again.
import java.sql.*;
/**
*
* @author
*/
// Static class for connecting to a database
public class connectDatabase
{
private static String databaseDriver = "jdbc:odbc
river={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() {
}
}
•
•
Join Date: Mar 2006
Posts: 7
Reputation:
Solved Threads: 0
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
river={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;
}
}
import java.sql.*;
/**
*
* @author Dave
*/
// Static class for connecting to a database
public class connectDatabase
{
private static String databaseDriver = "jdbc:odbc
river={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;
}
}
![]() |
Similar Threads
- illegal start of expression (Java)
- JAVA Illegal Start of Expression Error (Java)
- Fibonacci Recursion - Illegal Start of expression! (Java)
- illegal start of expression (Java)
- Why illegal start of expression error? (Java)
- illegal start of expression (Java)
- Help on error message, illegal start an ';' expected (Java)
Other Threads in the Java Forum
- Previous Thread: clarify my doubt
- Next Thread: Source Code that don't work?
| Thread Tools | Search this Thread |
2dgraphics account android api apple applet application array arrays automation banking bidirectional binary binarytree birt bluetooth chatprogramusingobjects class classes client code columns component database derby design eclipse encryption error errors expand fractal game givemetehcodez graphics gui guidancer homework html ide if_statement image inetaddress inheritance integer intellij j2me java javadesktopapplications javaprojects jlabel jme jni jpanel jtextfield julia linux list map method methods midlethttpconnection mobile mobiledevelopmentcreatejar monitoring myaggfun netbeans newbie nullpointerexception open-source problem program project property recursion reference ria scanner search server set sms smsspam sort sourcelabs splash sql sqlite static stop string support swing testautomation threads tree ui unicode validation windows






