Hello,
I have such simple code:
Database.executeQuery("INSERT INTO Licence(LicenceNumber, LicenceCode)
VALUES ('" + l + "','" + c + "')");
ResultSet rs = Database.getQueryResult("SELECT * FROM Licence WHERE
LicenceNumber = '" + l + "' AND LicenceCode = '" + c + "'");
System.out.println("Number of rows = " + rs.getRow());
When I show these strings on the strings I got:
INSERT INTO Licence(LicenceNumber, LicenceCode) VALUES
('test','test123')
SELECT * FROM Licence WHERE (LicenceNumber = 'test' AND LicenceCode =
'test123')
Number of rows = 0
But when I look into database (MS Access) I see there that row.
Two above functions looks like that:
//------------------------------------------------------------------------------
public static void executeQuery(String query) {
Statement stmt;
try {
stmt = conn.createStatement();
stmt.executeUpdate( query );
stmt.close();
} catch (Exception e) {
e.printStackTrace();
}
}
//------------------------------------------------------------------------------
public static ResultSet getQueryResult(String query) {
Statement stmt;
try {
stmt = conn.createStatement();
ResultSet r = stmt.executeQuery( query );
return r;
} catch (Exception e) {
e.printStackTrace();
Error.getError(Error.DATABASE_READ_ERROR);
return null;
}
}
//------------------------------------------------------------------------------
p.s. I have also tried with conn.commit() but also with no success.
When I run the whole app again then I got correct results. Where is the
problem?!?
Best regards, mark
timoi - 16 Nov 2006 14:08 GMT
If I'm not totally wrong, I also had this problem with Access once. It
is a
database or database driver error. You may create a workaround by
closing the connection
and reopening it - a very expensive action.
By the way: You don't seem to like objects. Your class "Database" seems
to be a perfect candidate for an object as you use static functions and
(at least) the shared variable "conn". The "singleton pattern" (just
google for it) seems to be more adequate for me in such cases.
> Hello,
>
[quoted text clipped - 46 lines]
>
> Best regards, mark
panos - 17 Nov 2006 00:42 GMT
You are just interpreting the function incorrectly.
ResultSet.getRow() does not return the number of rows in the ResultSet.
It returns the *current* row number.
You have to iterate over the rows by using the functions next() and
then using the get functions to retrieve the actual row data.