Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / Databases / November 2006

Tip: Looking for answers? Try searching our database.

Problem with actualization

Thread view: 
mark - 13 Nov 2006 11:44 GMT
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.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.