Hello,
I am using the JDBC - ODBC Connection to access the data in my database designed in Access.
I have the following code:
boolean result = false;
String url = "";
Connection connection;
ResultSet rs;
boolean hasRecords = false;
// setup database connection
try {
url = "jdbc
dbc:imsqti";
Class.forName(" sun.jdbc.odbc.JdbcOdbcDriver"
;
Connection connect = DriverManager.getConnection(url);
}
catch (ClassNotFoundException cnfex)
{ message('r'," Error Connecting to DataBase"
;
cnfex.printStackTrace(); }
catch (SQLException sqlex)
{ message('r'," Error Connecting to DataBase"
;
sqlex.printStackTrace(); }
catch ( Exception ex)
{ message('r'," Error Connecting to DataBase"
;
ex.printStackTrace(); }
try {
// first error goes here
Statement statement = connection.createStatement();
String query = "SELECT * FROM Teacher WHERE TUsername = '"+
logid + "' AND TPassword = '" + password + "'";
rs = statement.executeQuery(query);
statement.close();
}
catch (SQLException sqlex)
{ message('r'," Error Connecting to DataBase"
;
sqlex.printStackTrace(); }
try {
// second error goes here
hasRecords = rs.next();
if (hasRecords)
{ result = true;
message('g'," Welcome "+logid); }
else {
result = false;
message('r'," Invalid UserName or Password. Please try again"
; }
}
catch (SQLException sqlex)
{ message('r'," Error Connecting to DataBase"
;
sqlex.printStackTrace(); }
return result;
But i get the error:
variable connection might not have been initialised
for the first bolded line, and
variable connection might not have been initialised
for the second bolded line..
Any ideas?
I am using the JDBC - ODBC Connection to access the data in my database designed in Access.
I have the following code:
boolean result = false;
String url = "";
Connection connection;
ResultSet rs;
boolean hasRecords = false;
// setup database connection
try {
url = "jdbc
Class.forName(" sun.jdbc.odbc.JdbcOdbcDriver"
Connection connect = DriverManager.getConnection(url);
}
catch (ClassNotFoundException cnfex)
{ message('r'," Error Connecting to DataBase"
cnfex.printStackTrace(); }
catch (SQLException sqlex)
{ message('r'," Error Connecting to DataBase"
sqlex.printStackTrace(); }
catch ( Exception ex)
{ message('r'," Error Connecting to DataBase"
ex.printStackTrace(); }
try {
// first error goes here
Statement statement = connection.createStatement();
String query = "SELECT * FROM Teacher WHERE TUsername = '"+
logid + "' AND TPassword = '" + password + "'";
rs = statement.executeQuery(query);
statement.close();
}
catch (SQLException sqlex)
{ message('r'," Error Connecting to DataBase"
sqlex.printStackTrace(); }
try {
// second error goes here
hasRecords = rs.next();
if (hasRecords)
{ result = true;
message('g'," Welcome "+logid); }
else {
result = false;
message('r'," Invalid UserName or Password. Please try again"
}
catch (SQLException sqlex)
{ message('r'," Error Connecting to DataBase"
sqlex.printStackTrace(); }
return result;
But i get the error:
variable connection might not have been initialised
for the first bolded line, and
variable connection might not have been initialised
for the second bolded line..
Any ideas?