: : : : : Alright, here is is how I solved it:
: : : : :
: : : :
: : : : : private int findPK(int position)
: : : : : {
: : : : : int stop = 0;
: : : : : String sqlCommand = "SELECT Kundnr FROM Kundtabell";
: : : : : try {
: : : : : Statement s = connection.createStatement();
: : : : : ResultSet rs = s.executeQuery(sqlCommand);
: : : : : while(stop < position) {
: : : : : stop++;
: : : : : rs.next();
: : : : : }
: : : : : return rs.getInt(1);
: : : : : }
: : : : : catch(SQLException err) {
: : : : : System.out.println("Fel: " + err.getMessage());
: : : : : }
: : : : :
: : : : : return 1;
: : : : : }
: : : :
: : : :
: : : : Looks like a perfectly reasonable solution, but I still must reiterate that unless your DBMS implicitly order your records via an index or some other mechanism, this is not guaranteed to return the same record every time it runs.
: : : :
: : : :
: : : :
infidel
: : : :
: : : :
: : :
: : : Holy crud... This is way over the top unneccessary.
: : :
: : : You'd be better off creating a temporary table and putting a sequential ID in a column and using that as a key to get your record.
: : :
: : : You MUST do one of two different things. Keep an active cursor or keep a cache of the data. If you cache the data, keep a timestamp so you know if the data has been "touched." Really you could probably just cache the PK column(s) for the data in your query.
: : :
: : : What's going to happen when your user is on rec3 for a few minutes and rec2 was deleted? When he clicks next will he get the original rec4 or the new rec4? And when the user starts giving you wacky descriptions about inconsistencies in the data what will you do? As if it wasn't hard enough to get useful info from a user, let's give them problems that are NOT REPRODUCABLE. OMG.
: : :
: : : Of course, you can completely disregard all of this if you don't mind your app working like crap.
: : :
: : : Sorry, I'm a little cranky that the matrix hasn't been released over here yet... I'll feel better tonight :)
: : :
: : : -ray
: :
: : Well, the database is simply a local one. Data inconsistencies has to do with simultaneous users trying to update the database. And I believe I could temporary store the PKs in a vector or something, but would it improve the performance significantly or did you suggest that only because you think elegancy == good performance? I would still have to update the buffer every time I delete or add a record.
: :
: : Btw, it sucks (Matrix) :)!
: :
: : /Mordien
: :
:
: First let me say that my suggestions weren't an effort to inject elegance, its an effort to inject accuracy. It isn't elegant anyway. I would call this a last ditch effort to preserve data integrity which your code violates in a number of different ways. There are reasons why locks exist but I'm pretty much out of gas on this debate so I'm not going to go into it.
:
: Second, yes, it'll perform better if you can ID the row and request it. Rather than scanning the entire set yourself. This'll be more evident at the end of the recordset. You're effectively doing a manual tablescan. This is the slowest thing that can be done by the dbms and I'm positive that it'll be slower on the client side and you're moving ALL the records to the client (even if the data is on the same machine, it needs to be moved process to process). As a bonus, you are only moving one record and you have less traffic.
:
: I don't understand what you are doing. Anytime a programmer justifies violating data integrity because "my situation doesn't need it" is completely beyond me. All code should work properly. If you expect that your code will be so worthless that it'll never inspire others to use it... what can I say. You're probably right because that's always be a self-fulfilling prophecy. When even the programmer doesn't respect the software, noone will. Even if you are right, I'd take the 5 minutes and guarantee data integrity. I think of data integrity as being sacred and my coding efforts show it. If you don't think the same way... your's will show that as well, believe me.
:
: I saw the matrix and "sucks?" It wasn't the greatest I've ever seen, special effects aside, but it was up there on the list. Special effects were definitely top 3. The SE were innovative and stunning but they lost points for SE looking fake/contrived. The whole idea is for SE to make you believe you are watching real events, not thinly disguised Comp Anim. Neo looked really fake quite a few times.
:
: -Ray
Hi!
I cant believe this. This is quite some words for someone who has only a vague concept of what data integrity is. I am not violating the principle about data integrity in anyway. Data integrity "protects" the data from having null values, unreasonable values, no duplicate tuples etc.
Somehow I also get the feeling you didnt quite understand what the initial topic was all about. Anyway, the program works nicley, thank you. Im not angry or anything, but other people who responded at least tried to help me whereas you are stuck with your "coding principles" BS.
Anyway, sure Matrix has awesome special effects, but too ridiculous to be taken seriously. But K1 in las Vegas tonight, thats something!
/Mordien
:
:
:
:
:
:
: