code logs -> 2008 -> Sat, 22 Mar 2008< code.20080321.log - code.20080323.log >
--- Log opened Sat Mar 22 00:00:17 2008
01:12 Mango [~Mango@24.86.100.ns-4243] has quit [Quit: Mango]
01:44 AnnoDomini [AnnoDomini@83.21.20.ns-2986] has quit [Quit: Some people find sanity a little confining.]
02:06 Vornicus [~vorn@ServicesOp.Nightstar.Net] has quit [Connection reset by peer]
02:08 Vornicus [~vorn@Admin.Nightstar.Net] has joined #code
02:08 mode/#code [+o Vornicus] by ChanServ
02:36 Doctor_Nick [~nick@Nightstar-24048.hsd1.fl.comcast.net] has joined #code
04:07 Doctor_Nick [~nick@Nightstar-24048.hsd1.fl.comcast.net] has quit [Quit: Konversation terminated!]
05:23
< Kazriko>
AFKSkull, if they're in linux, then all they need to do is make an external call to "eject" :)
06:59 GeekSoldier|bed is now known as GeekSoldier
07:00 Kazriko [~kaz@Nightstar-26352.gdj-co.client.bresnan.net] has quit [Operation timed out]
07:04 Kazriko [~kaz@72.174.26.ns-12779] has joined #code
07:05 Kazriko is now known as NSGuest-5633
07:05 NSGuest-5633 is now known as Kaz
08:27 Vornicus is now known as Vornicus-Latens
08:33 GeekSoldier [~Rob@Nightstar-10842.dip.t-dialin.net] has quit [Ping Timeout]
08:37 GeekSoldier [~Rob@Nightstar-10678.dip.t-dialin.net] has joined #code
08:37 mode/#code [+o GeekSoldier] by ChanServ
09:07 AnnoDomini [AnnoDomini@83.21.20.ns-2986] has joined #Code
09:07 mode/#code [+o AnnoDomini] by ChanServ
09:12 AFKSkull [~none@Nightstar-7066.dyn.optonline.net] has quit [Ping Timeout]
09:13 AFKSkull [~none@Nightstar-7066.dyn.optonline.net] has joined #code
10:07 Vornicus-Latens [~vorn@Admin.Nightstar.Net] has quit [Ping Timeout]
11:10
<@AnnoDomini>
I has a question. I have a method that I want to return a ResultSet (an object that contains the result of a Query), but it looks very icky. I apparently have to close it after use or something.
11:11
<@AnnoDomini>
It's troublesome to describe.
11:12
<@AnnoDomini>
http://pastie.caboo.se/169054 <- Here's what I'm trying, but it says ResultSet is abstract. (Not that I know what that means.)
11:13
<@AnnoDomini>
What I want to accomplish is a more readable handling of database stuff, with all that try-catch exception handling delegated to a separate class.
11:14
<@jerith>
Don't initialise resset.
11:14
<@AnnoDomini>
SZRBD.java:200: variable resset might not have been initialized
11:14
<@AnnoDomini>
return resset;
11:15
<@jerith>
AFAICT, it's an interface or abstract class or something and you're actually using implementation-dependent subclasses.
11:15
<@jerith>
You're not setting it anywhere.
11:15
<@AnnoDomini>
I am!
11:15
<@jerith>
Oh, you are.
11:15
<@jerith>
Um.
11:15
<@AnnoDomini>
Deep within a nest of exceptions. :(
11:16
<@jerith>
Scratch the whole trying to assign thing. That will always succeed.
11:16
<@jerith>
You need to close the ResultSet after using it, I think.
11:16
<@jerith>
Although GC should do that for you.
11:16
<@AnnoDomini>
Uh... I don't follow.
11:17
<@AnnoDomini>
But how do I close it after I've return'ed?
11:17
<@jerith>
The ResultSet is actually an open connection to the DB.
11:17
<@jerith>
The caller deals with that.
11:17
<@jerith>
If you close it in executeQuery, you can't use it.
11:18
<@AnnoDomini>
Would I be able to get my data after I close it?
11:18
<@jerith>
Not afaik.
11:18
<@AnnoDomini>
Ick.
11:19
<@AnnoDomini>
So... what now? A dynamically created String array?
11:19
<@jerith>
It's actually a somewhat sane interface, when you realise that in some implementations it's just a wrapper around a cursor in the db.
11:19
<@jerith>
Return the ResultSet and close it in the caller.
11:20
<@AnnoDomini>
I don't understand. You mean I need to return rs, and then close it after where I've called the method from?
11:20
<@jerith>
Yes.
11:20
<@AnnoDomini>
Ick. But okay.
11:21
<@jerith>
IT's nothing you wouldn't have to do anyway.
11:22
<@jerith>
Treat executeQuery as "execute this query without having to mess with createStatement".
11:22
<@jerith>
In other words, just a thin abstraction for once-off queries.
11:24
<@AnnoDomini>
http://pastie.caboo.se/169055 <- Something like this? Sorry, I just can't wrap my head around this mess.
11:25
<@AnnoDomini>
I can't do it without the bloody exception handlers, and with thim, it doesn't recognize that the ResultSet has been set to something!
11:25
<@AnnoDomini>
*them
11:26
<@AnnoDomini>
Why, why, WHY isn't there a container for the results of a query?!
11:27
<@AnnoDomini>
I just want a nice container. ;_;
11:27
<@jerith>
OK, get rid of the innermost try block. You do *not* want to close rs in this method.
11:27
<@jerith>
And you're already returning it at the end.
11:27
<@jerith>
Now, try initialising rs to null up at the top.
11:28
<@AnnoDomini>
It compiles!
11:28
<@jerith>
Then, don't catch (or catch and rethrow) the exception.
11:29
<@AnnoDomini>
Uhhh?
11:29
<@jerith>
In this case, an exception is going to leave you with a broken ResultSet, so you don't want to try to contin\ue.
11:29
<@jerith>
-\
11:30
<@AnnoDomini>
You mean I shouldn't try-catch after the method returns?
11:30
<@jerith>
In fact, you can also make that cleaner by putting the stmt.close() finally block on the end of your outermost try.
11:30
<@jerith>
If you get an exception, you don't want to try to use rs. Thus, you need to know about it outside executeQuery().
11:31
<@jerith>
Since you're obliged to return a ResultSet, this means throwing an exception.
11:32
<@jerith>
Since anything that would break /already/ throws an exception, the easiest course of action is to just not catch it.
11:32
<@jerith>
Thus, your try/catch moves up the call stack to where you're trying to /use/ the ResultSet.
11:33
<@AnnoDomini>
http://pastie.caboo.se/169056 <- So, is this correct? And I shouldn't be catching an exception when I try to close the ResultSet that I get from the method, or what?
11:35
<@jerith>
You can kill the inner try/finally block and move the rs = [...] outside it.
11:36
<@jerith>
You already have a finally where you're closing stmt.
11:36
<@jerith>
You also want to either rethrow e4 or just not catch it in the first place.
11:37
<@AnnoDomini>
http://pastie.caboo.se/169057 <- Like this?
11:39
<@AnnoDomini>
http://pastie.caboo.se/169058 <- Well, I actually tried to compile this.
11:39
<@jerith>
Ah.
11:40
<@jerith>
Now you need to declare that you can throw java.sql.SQLException.
11:40
<@jerith>
"ResultSet executeQuery(String _query) throws java.sql.SQLException {" up at the top.
11:41
<@AnnoDomini>
Okay.
11:42
<@AnnoDomini>
http://pastie.caboo.se/169059 <- Here's the entire class so far, BTW. Can I use the "throws java.sql.SQLException" in all of these?
11:44
<@jerith>
The thing about exceptions in Java is that you need to either catch them or declare that you throw them.
11:44
<@jerith>
This means (theoretically) that you can be certain that you only need to deal with certain kinds of exceptions.
11:45
<@jerith>
In practice, most people just say "throws Exception" for everything.
11:45
<@AnnoDomini>
Cool.
11:46
<@AnnoDomini>
Even the constructor?
11:46
<@jerith>
So take out all the catches for things you don't specifically want to handle.
11:46
<@jerith>
I think so.
11:46
<@jerith>
I seldom do anything that can throw an exception in a constructor.
11:47
<@AnnoDomini>
Do I replace the catches with finallys? I remember it dislikes try without either catch or finally.
11:50
<@jerith>
If you don't have catch or finally, you don't need the try.
11:52
<@AnnoDomini>
Okay. I'm actually catching the thing in the constructor. It's a useful hint that the driver isn't installed. :)
11:53
<@jerith>
If you catch it without throwing anything, you log that it's not installed and then try to use it anyway.
11:53
<@jerith>
Which is a Bad Thing.
11:54
<@jerith>
The whole point of an exception is to let you know that something is wrong.
11:54
<@AnnoDomini>
So I should throw but not catch.
11:54 Thaqui [~Thaqui@Nightstar-123.jetstream.xtra.co.nz] has left #code [Leaving]
11:54
<@jerith>
If you can't make it right, let it propagate upwards.
11:54
<@jerith>
That way, you can catch it where you /can/ make it right.
11:56
<@jerith>
In the case of executeQuery(), you can't make it right when you make the query. Thus you leave it to the caller to decide whether to retry, display an error message, crash and burn or do something else.
11:56
<@AnnoDomini>
That'd mean propagating it to the user so that he installs the driver properly. :p
11:56
<@jerith>
Yes. If you can't do anything without the db driver, crash hard with an appropriate message.
11:57
<@jerith>
Your library should handle it by throwing an exception and let the application deal with it.
11:59
<@AnnoDomini>
How did you shut down the whole thing from code?
11:59 * AnnoDomini never had to use that before.
12:05
<@jerith>
exit(), I think.
12:10
<@AnnoDomini>
Doesn't work, but no matter. I'll do it another day. I've done enough for today.
12:11
<@jerith>
Especially a Saturday.
12:19 AnnoDomini [AnnoDomini@83.21.20.ns-2986] has quit [Ping Timeout]
12:26 AnnoDomini [AnnoDomini@83.21.18.ns-3061] has joined #Code
12:26 mode/#code [+o AnnoDomini] by ChanServ
12:49 Pi [~sysop@ServicesAdmin.Nightstar.Net] has quit [Ping Timeout]
13:46
<@AnnoDomini>
LOL. I've accidentally generated a sound that's reminiscent of the special UFO in Space Invaders.
13:47
<@GeekSoldier>
sweet
14:10 Serah [~Z@87.72.35.ns-26506] has quit [Connection reset by peer]
14:19
<@AnnoDomini>
...
14:19
<@AnnoDomini>
Why is there a "Lenovo-11355f87" server on my LAN?
14:19
<@AnnoDomini>
It's certainly nothing of mine.
14:19
<@GeekSoldier>
wireless connection?
14:20
<@AnnoDomini>
Possible. But I'll go check with the other dwellers of my household.
14:22
<@AnnoDomini>
Yeah, my sister chose a really strange name for her laptop.
14:22
<@AnnoDomini>
Or just accepted the RNG name.
14:22
<@GeekSoldier>
that sounds like a standard IBM name.
14:23
<@AnnoDomini>
Mmm.
14:23
<@ToxicFrog>
Yeah. By default its name is <model name>-<serial number hash>, IIRC
14:23
<@ToxicFrog>
Today's XKCD is delicious.
14:24
<@ToxicFrog>
Also, for shutting down the whole program in Java: System.exit()
14:25
<@AnnoDomini>
Any way to do the equivalent of DOS 'PAUSE'?
14:27
<@AnnoDomini>
And by that I mean "Press any key to continue..."
14:27
<@ToxicFrog>
Poor man's way is to read a line and "press enter to continue"
14:27
<@ToxicFrog>
(System.in is the stream object you want)
14:30
<@ToxicFrog>
Java 6 also has a Console class - check the API for details.
14:30
<@ToxicFrog>
Er, the API reference.
14:30
<@ToxicFrog>
It might do what you want.
14:30
<@AnnoDomini>
Seems there are only complex ways to do something that should be rather simple.
14:31
<@ToxicFrog>
Simple?
14:31
<@ToxicFrog>
Hah.
14:31
<@ToxicFrog>
The *right* way is to set the terminal to raw (ie, unbuffered non-echoing mode) and read a single character.
14:31
<@ToxicFrog>
Then set it back to cooked mode.
14:32
<@ToxicFrog>
There is no portable way of doing this.
14:35 * AnnoDomini mumbles about how it's only 2 assembly instructions.
14:35
<@AnnoDomini>
Well, the input part, anyway. :p
14:36
<@ToxicFrog>
Maybe if you're using a serial terminal.
14:36
<@ToxicFrog>
But most certainly not for any terminal emulator.
14:36 Serah [~Z@87.72.35.ns-26506] has joined #Code
14:36 mode/#code [+o Serah] by ChanServ
14:36
<@ToxicFrog>
In *nix you can do it fairly reliably with stty, which is actually tc(get|set)attr, which is actually ioctl.
14:37
<@ToxicFrog>
I have no idea how you do it in windows, although it's clearly possible since pause does it.
14:39
<@ToxicFrog>
However, Java provides no API to directly manipulate these settings.
14:43
<@AnnoDomini>
Well, DOS and the newer Command Prompt sport the input with echo software interrupt.
14:44
<@AnnoDomini>
INT 21,1
14:44
<@AnnoDomini>
INT 21,7 is without echo.
14:59 EvilDarkLord is now known as Zenon
15:29 C_tiger [~c_wyz@96.232.24.ns-12235] has quit [Ping Timeout]
18:02 C_tiger [~c_wyz@96.232.24.ns-12235] has joined #code
18:02 mode/#code [+o C_tiger] by ChanServ
18:07 Pi [~sysop@76.22.79.ns-4584] has joined #code
18:07 mode/#code [+o Pi] by ChanServ
18:13 Vornicus-Latens [~vorn@Admin.Nightstar.Net] has joined #code
19:00 Vornicus-Latens is now known as Vornicus
19:41 Zenon is now known as EvilDarkLord
20:27
<@McMartin>
AD: Only if running MS-DOS or an emulator thereof
20:28
<@McMartin>
That's the "Do MS-DOS system call" interrupt, IIRC.
20:28
<@AnnoDomini>
Yeah.
20:28
<@AnnoDomini>
It works under the WinXP Command Prompt, like I said.
20:36 GeekSoldier is now known as GeekSoldier|bed
20:46
<@ToxicFrog>
Which is, in fact, a DOS emulator.
20:46
<@ToxicFrog>
And not a very good one.
20:47 * AnnoDomini nods.
21:08 GeekSoldier|bed [~Rob@Nightstar-10678.dip.t-dialin.net] has quit [Ping Timeout]
21:19 Reiver [~reaverta@Admin.Nightstar.Net] has quit [Ping Timeout]
21:19 DiceBot [~Reiver@Nightstar-11274.xdsl.xnet.co.nz] has quit [Ping Timeout]
21:23 GeekSoldier|bed [~Rob@91.18.94.ns-3351] has joined #code
21:36 Serah [~Z@87.72.35.ns-26506] has quit [Connection reset by peer]
21:51 GeekSoldier|bed [~Rob@91.18.94.ns-3351] has quit [Ping Timeout]
21:53 Reiver [~reaverta@Nightstar-11274.xdsl.xnet.co.nz] has joined #Code
21:53 mode/#code [+o Reiver] by ChanServ
21:55 Serah [~Z@87.72.35.ns-26506] has joined #Code
21:55 mode/#code [+o Serah] by ChanServ
22:31 Mango [~Mango@24.86.9.ns-26788] has joined #code
22:31
< Mango>
I was having a monologue in the support channel but a customer came in
22:32
< Vornicus>
Heh
22:32
< Mango>
So I'll finish here unless anyone's in the middle of something
22:32
< Vornicus>
nope
22:33
< Mango>
Right, so, I need to write a set of modules that will work with both my POS and eCommerce systems
22:33
< Mango>
They will need to do the following things
22:33
< Mango>
1) Generate an HTML form to be filled in by users of the POS module and calculate the price of things with Javascript
22:33
< Mango>
2) There is no 2)
22:34
< Mango>
3) Calculate the price server-side for users of the website
22:34
< Mango>
4) Make any required changes to the database (inventory counts etc) to reflect the customers' purchases.
22:34
< Mango>
the POS won't use 3) because the staff may wish to override the default price, so pure Javascript will be fine there.
22:35
< Mango>
4 will likely be the tricky bit
22:35
< Mango>
Ideally, the data generated by 1) and 3) will be in the same format and passed to 4)
22:36
< Mango>
4) looks at it, validates it if necessary, and passes it to the db
22:36
< Mango>
so the data could be something like
22:38
< Mango>
array("Type"=>"Widget", "Quantity"=>"2", "Total"=>"20.00")
22:38
< Mango>
there may be multiple types
22:39
< Mango>
and each type will have its own #4 function
22:39
< Mango>
so either the eCommerce or POS program will call the appropriate #4 function
22:39
< Mango>
and pass Quantity, Total, and any other necessary variables
22:40
< Mango>
hmm, so there's possibly two things that will need to be inserted into the DB
22:41
< Mango>
first is the $ into the accounting system
22:41
< Mango>
second is the inventory transaction, if inventory is tracked for that item
22:41
< Mango>
so it seems like a logical order would be
22:41
< Mango>
a) Credit card auth
22:42
< Mango>
b) #4
22:42
< Mango>
now
22:42
< Mango>
does #4 do the accounting system and the inventory all in one go?
22:42
< Mango>
I think so.
22:43
< Mango>
In the event that no special transaction is necessary, the data could be passed to a "Default #4 function"
22:43
< Mango>
which simply does the accounting
23:18 * McMartin swears at Java's standard libraries.
23:18
<@McMartin>
Admittedly, I'd managed to go several years without noticing this, including the time when this wasn't supported at all
23:18
<@McMartin>
But seriously, can it really be too much to ask to let FileInputStream support ftell and fseek directly?
23:19
<@McMartin>
Or at least have *some* class that supports ftell and fseek and *also* lets you read from it?
23:19
< Vornicus>
23:19
< Vornicus>
you're kidding, right?
23:19
<@McMartin>
Nope.
23:19
<@McMartin>
The closest InputStream gets to this is mark and reset, neither of which are supported on files.
23:19
< Vornicus>
That's just silly.
23:20
<@McMartin>
To do an ftell or fseek you call getChannel on the FileInputStream
23:20
<@McMartin>
And the Channel can be relocated, but you can't read from it; you read from the stream object still.
23:20 * AnnoDomini want ResultSet-like containers.
23:21
<@McMartin>
Also, the seek/tell routines are not part of Channel, but FileChannel alone, so I can't be oblivious to whether I'm using a byte[] or a File.
23:21
<@McMartin>
Well
23:21
<@McMartin>
I lie slightly
23:21
<@McMartin>
I can easily write three classes that allow this.
23:21
< Vornicus>
But the fact that it doesn't otherwise exist is just silly.
23:22
<@McMartin>
Yes.
23:22
<@McMartin>
Well, sort of.
23:22
<@McMartin>
It's OK that InputStream lacks it.
23:22
<@McMartin>
Because InputStream is also for things like, say, sockets.
23:22
<@McMartin>
And I have no real objection to not being able to fseek sockets.
23:22
<@McMartin>
Or stdin.
23:23
<@McMartin>
... I suppose you could just never cache the FileChannel
23:23
<@McMartin>
So that fseek becomes, say, "fis.getChannel().position(x);" or whatnot.
23:25
<@McMartin>
Looks like the mcmutil package will be getting a few new classes.
23:25
<@McMartin>
Though I don't have a good name for it.
23:25
<@McMartin>
IndexedInputStream?
23:26
< Vornicus>
Seekable
23:29
<@McMartin>
That's good for the interface, I guess. How about for the file/byte array versions?
23:29
<@McMartin>
"SeekableByteArray" sounds wrong, but everything else is waaaaay to verbose.
23:30
<@McMartin>
Mmm. I guess FileSeekable and ByteArraySeekable fit the normal name conventions better.
--- Log closed Sun Mar 23 00:00:28 2008
code logs -> 2008 -> Sat, 22 Mar 2008< code.20080321.log - code.20080323.log >