Home arrow static arrow Java Programming [Archive] - ResultSet methods dont work...?
Warning: Creating default object from empty value in /www/htdocs/w008deb8/wiki/components/com_staticxt/staticxt.php on line 51
Java Programming [Archive] - ResultSet methods dont work...?
This topic has 60 replies on 5 pages.    « Previous | 1 | 2 | 3 | 4 | 5 | Next »

Posts:21,718
Registered: 98-02-20
Re: ResultSet methods dont work...?  
Aug 2, 2004 10:51 AM (reply 30 of 60)



 
Obviously you meant java.lang.Throwable, but yeah!

Actually, I did mean java.lang.RuntimeException, because I was only thinking of unchecked exceptions.

If you want to go the full monty, by all means change it to java.lang.Throwable and include Errors in there, too.

%
 

Posts:343
Registered: 7/13/04
Re: ResultSet methods dont work...?  
Aug 2, 2004 10:53 AM (reply 31 of 60)



 
well, now i'm lost in this conversation, i guess i'll just delete a large portion and try to start over from what i learned here.
 

Posts:6,750
Registered: 1/25/04
Re: ResultSet methods dont work...?  
Aug 2, 2004 10:54 AM (reply 32 of 60)



 
3. I don't see where you call rs.next().
i do the rs.next method but it has the EXACT same
effect as when i call any other method in the
ResultSet class

Can you post the version where you call rs.next(), and describe exactly what happens?
 

Posts:21,718
Registered: 98-02-20
Re: ResultSet methods dont work...?  
Aug 2, 2004 10:59 AM (reply 33 of 60)



 
the reason i throw an EOFExeption is because i read a file in the line just below the try { statement

Where does this EOFException come from? It's not in my javadocs for JDK 1.4.

Nor should it be. An EOF condition is not an exceptional situation; it's the normal thing that happens when you come to the end of a file. The stream and reader classes will handle this just fine without throwing an exception.

If this is part of your company's standard API, I'd say it's a poor design.

2. In ins (bad method name BTW) you catch Exception
i'm sure its a bad method name becasue i've been
barely working as a computer programmer for 3 weeks
now and never went to any schooling for it.

Is this a joke? You have no training, you've been working for three weeks, and somebody has put you in charge of writing a persistence layer? Do you know anything about relational databases or SQL?

i'm
really trying my best to learn all the techniques and
norms for things. i've been able to learn just what
i've been able to teach myself online (the java
tutorials), and in these forums.

You need a senior person to work with you on this.

and squash it while you throw Exception from your
method. Why? What is the point of that? I saw
i have no idea! hehehe

It won't be funny to your clients.

i'm sure you would love to understand it I'D EVEN LIKE TO UNDERSTAND IT! ;)

i do the rs.next method but it has the EXACT same
effect as when i call any other method in the
ResultSet class

I don't know what you mean by this, but it's quite wrong. I don't see any call to next().

i didn't realize such a thing existed

Do yourself a favor and go out a buy a book about JDBC before you hurt yourself.

%
 

Posts:343
Registered: 7/13/04
Re: ResultSet methods dont work...?  
Aug 2, 2004 11:00 AM (reply 34 of 60)



 
oh actually i was wrong, rs.next(); DOESN'T mess up, its still the other part: rs.getInt("id");
ok this is EXACTLY what happens:
after it gets to that part: rs.getInt("id") it calls lots of other classes and eventually gets to a loop in a class called: "EventDispatchThread" and then i lose it after that. i push the F8 key which jumps to the next line but it "doesn't work" anymore. so i just have to terminate the program

                try {                        array = ReadData.ReadMessage(in);  // read each message and store in byte array: array.                        if (messageExists){	//assuming message exists, SQL statement stores data                               rs = sql.ins("INSERT INTO FrameData (" +                                                "FrameNumber, MessageId, PlatformId, TaskId, ParentId, TimeOfDay" +                                                        ") VALUES (" +                                                        frame + "," +                                                        mid + "," +                                                        pid + "," +                                                        tid + "," +                                                        paid + "," +                                                        day + ")");                                  rs.next();                                  int id = rs.getInt("ID");                                  System.out.println(id);                                 sql.gStmt.close();//                                     sql.getBlob(row,array);                                }                        }catch (EOFException error) {                                error.printStackTrace();
 

Posts:343
Registered: 7/13/04
Re: ResultSet methods dont work...?  
Aug 2, 2004 11:06 AM (reply 35 of 60)



 
the reason i throw an EOFExeption is because i read
a file in the line just below the try { statement

Where does this EOFException come from? It's not in
my javadocs for JDK 1.4.

so what should i replace EOFException with? just error.printstacktrace();?

Nor should it be. An EOF condition is not an
exceptional situation; it's the normal thing that
happens when you come to the end of a file. The
stream and reader classes will handle this just fine
without throwing an exception.

If this is part of your company's standard API, I'd
say it's a poor design.
not its not company standard there is no company standard that i know of its just what i've done

Is this a joke? You have no training, you've been
working for three weeks, and somebody has put you in
charge of writing a persistence layer? Do you know
anything about relational databases or SQL?
nope no joke, i dont know what a persistence layer is, but i do know about databases and sql sort of, since i got here 3 weeks ago i've been reading a LOT about databases and programming and so forth (unfortnately its not a joke that i'm here)


i'm
really trying my best to learn all the techniques
and
norms for things. i've been able to learn just what
i've been able to teach myself online (the java
tutorials), and in these forums.

You need a senior person to work with you on this.
there is one java expert that helps me but i can only meet with him about once a week, as he has his own asignments and is quite busy
 

Posts:21,718
Registered: 98-02-20
Re: ResultSet methods dont work...?  
Aug 2, 2004 11:08 AM (reply 36 of 60)



 
not its not company standard there is no company standard that i know of its just what i've done

Then you've done it wrong.

nope no joke, i dont know what a persistence layer is,
but i do know about databases and sql sort of, since i
got here 3 weeks ago i've been reading a LOT about
databases and programming and so forth (unfortnately
its not a joke that i'm here)

You'd better start reading faster.

there is one java expert that helps me but i can only
meet with him about once a week, as he has his own
asignments and is quite busy

Your boss should be flogged for leaving this with you.

%
 

Posts:21,718
Registered: 98-02-20
Re: ResultSet methods dont work...?  
Aug 2, 2004 11:09 AM (reply 37 of 60)



 
Please replace the mess you posted with this:

try {    array = ReadData.ReadMessage(in);  // read each message and store in byte array: array.    if (messageExists)    {        rs = sql.ins("INSERT INTO FrameData ("            + "FrameNumber, MessageId, PlatformId, TaskId, ParentId, TimeOfDay"            + ") VALUES ("            + frame + ","            + mid + ","            + pid + ","            + tid + ","            + paid + ","            + day + ")");  / What Java type is day, and what column type is it in your database?                                          int id = -1;        while (rs.next())        {                    id = rs.getInt(1);            System.out.println(id);        }//        sql.gStmt.close();  // Now that your global statement has been closed,                              // how do you intend to reinitialize it?  Awful stuff.        rs.close();                                                            //        sql.getBlob(row,array);    }    catch (SQLException e)     {        System.err.println("SQL state: " + e.getSQLState());        System.err.println("SQL error: " + e.getErrorCode());        e.printStackTrace();    }    catch (Exception e)    {        e.printStackTrace();    }


At least if there's a SQLException you might find out what's going on.

Once again - are you sure that the MySQL driver you're using supports getting generated keys back? If not, all this is a waste of time and you'll have to do something else.

%
 

Posts:21,718
Registered: 98-02-20
Re: ResultSet methods dont work...?  
Aug 2, 2004 11:27 AM (reply 38 of 60)



 
Just found [url=http://mmmysql.sourceforge.net/]this[/url]:

"New features from the JDBC-3.0 API in MySQL Connector/J include getGeneratedKeys which allows users to retrieve auto-increment fields in a non-database-specific way. Auto-increment fields now work with object-relational mapping tools as well as Enterprise Java Beans (EJB) servers with Container Managed Persistence (CMP) that support JDBC-3.0."

So it looks like the latest version of the MySQL Connector/J supports generated keys. Make sure you have the right version.

%
 

Posts:343
Registered: 7/13/04
Re: ResultSet methods dont work...?  
Aug 2, 2004 11:32 AM (reply 39 of 60)



 
ok, ya i just checked i have the latest version of MySQL

(and i'm thinking I'M the one that should get flogged, i told my boss i can learn this stuff no problem hehehe)
 

Posts:21,718
Registered: 98-02-20
Re: ResultSet methods dont work...?  
Aug 2, 2004 11:33 AM (reply 40 of 60)



 
Another thought:

        // Looks like you're closing a statement associated with the sql object.        sql.gStmt.close();          // Looks like you want to get a BLOB from the database here.  Do you try to reuse the statement that        // you just closed?  That can't work, can it?        sql.getBlob(row,array);


The way you're dealing with statements and scope is terrible. Keep the scope of objects as narrow as possible. Global things will always, always get you in trouble.

If you don't know what scope means, better do more research.

%
 

Posts:343
Registered: 7/13/04
Re: ResultSet methods dont work...?  
Aug 2, 2004 11:34 AM (reply 41 of 60)



 
OH MY GOSH YOU ARE MY SAVIOR!!!! YOUR CODE SNIPPET WORKED THANK YOU SOOOO MUCH!!!
 

Posts:21,718
Registered: 98-02-20
Re: ResultSet methods dont work...?  
Aug 2, 2004 11:34 AM (reply 42 of 60)



 
ok, ya i just checked i have the latest version of MySQL

Very good.

(and i'm thinking I'M the one that should get flogged,
i told my boss i can learn this stuff no problem
hehehe)

Or, worse, fired.

You might be able to learn it. The problem will come if your timetable is different from your boss's expectation.

%
 

Posts:343
Registered: 7/13/04
Re: ResultSet methods dont work...?  
Aug 2, 2004 11:35 AM (reply 43 of 60)



 
well, now i have an integer value that i can use to get the blob working (no i use a different statement to do the blob)
 

Posts:21,718
Registered: 98-02-20
Re: ResultSet methods dont work...?  
Aug 2, 2004 11:35 AM (reply 44 of 60)



 
A word of advice:

When you're working with a technology that you've never used before, like auto generated keys, write a small, simple command line app that exercises it before trying to incorporate it into a big lump of code. Smaller is better, especially for understanding.

%
 
This topic has 60 replies on 5 pages.    « Previous | 1 | 2 | 3 | 4 | 5 | Next »