comp.lang.java.programmer http://groups-beta.google.com/group/comp.lang.java.programmer [EMAIL PROTECTED]
Today's topics: * jdbc question - 3 messages, 3 authors http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/bab6d8d5c6089b91 * Using anchor tags in struts - 3 messages, 3 authors http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/74fff906636dadfd * [JSP] Help with Design decision - 1 messages, 1 author http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/7906830f6d90dea6 * decompress Huffmann with java.util.zip? - 2 messages, 2 authors http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/bc84c8df57c427a * Looking for a class similar to 'opendir' and 'readdir' - 1 messages, 1 author http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/815039ea9d4f6366 * ip string to long and back again - 2 messages, 2 authors http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/e5c9c07b6c5b6449 * Reverse Engineering, class diagram - 1 messages, 1 author http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/e3e67940724fa9b2 * about java API help under linux - 2 messages, 2 authors http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/64ce8146473a87d0 * field name for jOptionPane when using Eclipse? - 1 messages, 1 author http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/ecc8b53a68d74225 * Is there a Class like HashMap, but... - 8 messages, 3 authors http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/90f6b5fefbb8ee0a * maintain data in tabs in JSP pages - 1 messages, 1 author http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/f88868e021fdf086 ============================================================================== TOPIC: jdbc question http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/bab6d8d5c6089b91 ============================================================================== == 1 of 3 == Date: Wed, Dec 29 2004 7:59 pm From: Mark Thornton Virgil Green wrote: > Peter wrote: > >>"Chris Uppal" <[EMAIL PROTECTED]> skrev i en >>meddelelse news:[EMAIL PROTECTED] >> >>>jmt wrote: >>> >>> >>>>Using JDBC , what would be a more elegant way of determining >>>>whether or not a record already exists in a DB table before >>>>inserting it? >>> >>>Just attempt to insert it and catch and recover from the error (if >>>any). >> >>And if there is an error, I assume it is an SQLException. How does the >>application know the reason for the exception, and therefore can >>determine the action to take to recover? As far as I can determine >>there are no sub-classes of SQLException, or "type" values, or any >>other indication of the actual cause of the exception: for example, >>primary key exception, row not found, sql error.... >> > > > By examining the properties of SQLException. The methods getErrorCode() > and/or getSQLState would lead you to the underlying cause of the exception. > Not easily. There are several ways you might do this: 1. getErrorCode() this is dependent on the database vendor (and perhaps the JDBC driver as well). 2. getSqlState. There are two possible standards for these codes. Possible values for an already existing row might be "23000", "40002" or "44000". 3. getMessage() This again is database and JDBC driver dependent. I don't see any "Write Once Run Anywhere" option here. In most cases this approach will require individual testing and coding for each database/driver combination. By contrast the query to find if the row exists can be written to work unchanged on most databases, although as you point out it is likely to be slower. Where a number of rows are to be inserted/updated a batch query could be used to determine row existence for many rows at a time. This would reduce the number of round trips to the database and thus improve performance (at least where batch queries are available and implemented sensibly). Mark Thornton == 2 of 3 == Date: Wed, Dec 29 2004 10:02 pm From: ByteCoder jmt wrote: > Using JDBC , what would be a more elegant way of determining whether or > not a record already exists in a DB table before inserting it? > > Jeff > Registered Linux user number 366042 A last resort solution might be to run a query against the database to check if the record already exists. -- ------------- - ByteCoder - ...I see stupid people ------------- Curiosity *Skilled* the cat == 3 of 3 == Date: Wed, Dec 29 2004 9:29 pm From: "Virgil Green" Mark Thornton wrote: > Virgil Green wrote: >> Peter wrote: >> >>> "Chris Uppal" <[EMAIL PROTECTED]> skrev i en >>> meddelelse news:[EMAIL PROTECTED] >>> >>>> jmt wrote: >>>> >>>> >>>>> Using JDBC , what would be a more elegant way of determining >>>>> whether or not a record already exists in a DB table before >>>>> inserting it? >>>> >>>> Just attempt to insert it and catch and recover from the error (if >>>> any). >>> >>> And if there is an error, I assume it is an SQLException. How does >>> the application know the reason for the exception, and therefore can >>> determine the action to take to recover? As far as I can determine >>> there are no sub-classes of SQLException, or "type" values, or any >>> other indication of the actual cause of the exception: for example, >>> primary key exception, row not found, sql error.... >>> >> >> >> By examining the properties of SQLException. The methods >> getErrorCode() and/or getSQLState would lead you to the underlying >> cause of the exception. >> > > Not easily. There are several ways you might do this: > 1. getErrorCode() this is dependent on the database vendor (and > perhaps the JDBC driver as well). > 2. getSqlState. There are two possible standards for these codes. > Possible values for an already existing row might be "23000", "40002" > or "44000". > 3. getMessage() This again is database and JDBC driver dependent. Quite true... > I don't see any "Write Once Run Anywhere" option here. If WORA is the goal, then you must, indeed, code to the least common denominator. I expect that most code is written with a target database in mind and a small likelihood of another database replacing it. Every situation would have different requirements. > In most cases > this approach will require individual testing and coding for each > database/driver combination. Values to compare against as well as instructions for which property of the SQLException should be checked can be stored in a configuration file. Perhaps the same file in which you stored the URL of the JDBC driver. Database access could even be abstracted so that you don't have to worry about the differences in the majority of your code. - Virgil ============================================================================== TOPIC: Using anchor tags in struts http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/74fff906636dadfd ============================================================================== == 1 of 3 == Date: Wed, Dec 29 2004 12:06 pm From: [EMAIL PROTECTED] Ryan, 1.) Ignore the markup, it's my bad - me, thinking that I needed it in google - this new format threw me a bit. 2.) The anchor is ignored because the test I run expects the Logon jsp page to be rendered from where the anchor tag is located on that page. As I research this a bit more. It appears that there is no way of doing this - the anchor is stripped away and ignored - the browser's only interest is in rendering the page. Rather than slog through Struts source can anyone identify a method that can override Struts to acheive this effect? == 2 of 3 == Date: Wed, Dec 29 2004 3:35 pm From: "Ryan Stewart" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > Ryan, > > 1.) Ignore the markup, it's my bad - me, thinking that I needed it in > google - this new format threw me a bit. > > 2.) The anchor is ignored because the test I run expects the Logon jsp > page to be rendered from where the anchor tag is located on that page. > > As I research this a bit more. It appears that there is no way of > doing this - the anchor is stripped away and ignored - the browser's > only interest is in rendering the page. > > Rather than slog through Struts source can anyone identify a method > that can override Struts to acheive this effect? > Ah, right. I forgot about this. Supposedly it will work in some configurations if you set redirect="true" on the forward, but that loses the original request. The one thing I could think of would be to put the anchor name in your form action: <html:form action="logon.do#foo"> It's not a perfect fix, but it's not a perfect world. == 3 of 3 == Date: Wed, Dec 29 2004 5:12 pm From: Sudsy [EMAIL PROTECTED] wrote: <snip> > As I research this a bit more. It appears that there is no way of > doing this - the anchor is stripped away and ignored - the browser's > only interest is in rendering the page. Half right. See below. > Rather than slog through Struts source can anyone identify a method > that can override Struts to acheive this effect? You have to recognize that it's the browser which is scrolling to a named anchor. Unless you perform a redirect (in which case the browser will /know/ what target it's looking for) then you're SOL. Of course if you redirect then you lose everything in page and request scopes... ============================================================================== TOPIC: [JSP] Help with Design decision http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/7906830f6d90dea6 ============================================================================== == 1 of 1 == Date: Wed, Dec 29 2004 9:41 pm From: "Marcus Reiter" I have a list of data coming from the database that shows me tests and wether or not people (showing their id) have signed up for them already or not yet. Using plain JSP I need to create a checkbox for each of those values and if that person has already signed up for that test it needs to be checked, while it needs to be unchecked if the person has not yet signed up. It also has should be possible to check / uncheck checkboxes and then to add / delete values from the database. How would you design this? For one person, I thought about an array that has the name of the test and then in the next field wether or not the person has signed up for this test or not. Now in the jsp a new array will be created. Would you compare both arrays and just update those values that have changed or would you just delete all entries of that person and recreate all entries? What easier / better in performace / better design whise? Any ideas? Thanks, Marcus ============================================================================== TOPIC: decompress Huffmann with java.util.zip? http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/bc84c8df57c427a ============================================================================== == 1 of 2 == Date: Wed, Dec 29 2004 9:53 pm From: "Andrey Kuznetsov" >> I know that Zip uses Huffmann-Compression. >> Is there some way to (mis)use Deflater or may be >> ZipInputStream to decompress data compressed with Huffman compression? > > No. :-( -- Andrey Kuznetsov http://uio.dev.java.net Unified I/O for Java http://reader.imagero.com Java image reader http://jgui.imagero.com Java GUI components and utilities == 2 of 2 == Date: Wed, Dec 29 2004 10:00 pm From: ByteCoder Andrey Kuznetsov wrote: >>>Hi all, >>> >>>I know that Zip uses Huffmann-Compression. >>>Is there some way to (mis)use Deflater or may be >>>ZipInputStream to decompress data compressed with Huffman compression? >> >>If Huffmann compression is the default for any zip file than yes, you can >>use the zipinputstream. > > > what is zipinputstream? Do you mean java.util.zip.ZipInputStream? > ZipInputStream is awaiting data in defined format so may be I have to > prepare > my data. > Sorry, I meant java.util.zip.ZipInputStream. -- ------------- - ByteCoder - ...I see stupid people ------------- Curiosity *Skilled* the cat ============================================================================== TOPIC: Looking for a class similar to 'opendir' and 'readdir' http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/815039ea9d4f6366 ============================================================================== == 1 of 1 == Date: Wed, Dec 29 2004 1:57 pm From: Chris Smith Ramon <[EMAIL PROTECTED]> wrote: > I need to write a simple utility which will navigate > several subdirectories and query the file size of > some files. > > I am very familiar with the Unix 'opendir' and 'readdir' > functions, and that's what I am looking for, except > that this time I need something for Java, and the > utility will be run on a Windows PC. See java.io.File and its methods. Specifically, if you have a known starting point as a path string, create a File object to represent it, a la: File myDir = new File(path); Then use listFiles to get the contents of the directory: File[] contents = myDir.listFiles(); Then use the various methods of java.io.File (see the API docs for details) to get the attributes of the file: for (int i = 0; i < contents.length; i++) { File f = contents[i]; System.out.println(f.getName() + ": " + f.length()); } (or, in the new Java 1.5) for (File f : contents) { System.out.println(f.getName() + ": " + f.length()); } > Also: has Java been able to come up with a working > 'chdir()' (on Windows, that is)? Last time I checked > the C++ chdir function in Windows exists and succeeds > but it is bogus, since doesn't really change the program's > default directory. Java has never provided an API for changing the current working directory. However, as of Java 1.3, you can specify the working directory for any subprocesses created via Runtime.exec calls. I don't know what your complaint is with changing the current working directory on Windows from C++. There is no 'chdir' function on Windows, since chdir is specified by POSIX and not by ANSI C or C++. There is, however, a Win32 API function called SetCurrentDirectory. There are also functions called _chdir and _wchdir in the Microsoft Visual C++ runtime library, which are fairly similar to POSIX chdir. These all seem to work, but it may lead to undefined results to use them in native code from a multithreaded (meaning pretty much any) Java application. -- www.designacourse.com The Easiest Way To Train Anyone... Anywhere. Chris Smith - Lead Software Developer/Technical Trainer MindIQ Corporation ============================================================================== TOPIC: ip string to long and back again http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/e5c9c07b6c5b6449 ============================================================================== == 1 of 2 == Date: Wed, Dec 29 2004 10:04 pm From: ByteCoder Michiel Konstapel wrote: >>> Another thing that does not seem to have occured to anyone - a long is >>> not long enough to hold an IPv6 address. And any code that assumes that >>> IP addresses are only 4 bytes is broken. >> >> >> Thanks for the info. I thought a long had more memory available than >> an int. Guess not. > > > It does, 8 bytes vs 4 for an int. But an IPv6 address is 128 bits or 16 > bytes. > Michiel Roger that. :) -- ------------- - ByteCoder - ...I see stupid people ------------- Curiosity *Skilled* the cat == 2 of 2 == Date: Wed, Dec 29 2004 9:26 pm From: "Ann" "Michiel Konstapel" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > >> Another thing that does not seem to have occured to anyone - a long is > >> not long enough to hold an IPv6 address. And any code that assumes that > >> IP addresses are only 4 bytes is broken. > > > > Thanks for the info. I thought a long had more memory available than an > > int. Guess not. > > It does, 8 bytes vs 4 for an int. But an IPv6 address is 128 bits or 16 > bytes. > Michiel Does IPv6 use dot notation? If so, are the number ranges larger or are there more numbers, (or both?) ============================================================================== TOPIC: Reverse Engineering, class diagram http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/e3e67940724fa9b2 ============================================================================== == 1 of 1 == Date: Wed, Dec 29 2004 1:16 pm From: "GregSmith" check out togethersoft and borland jbuilder/jdeveloper. greg Hans Stoessel wrote: > Hi > > I have several Java- and C++-Projects. Now I would like to generate class > diagrams from this projects. I'm looking for a (Windows-)freeware or > shareware tool to do that. Does somebody knows such a tool? > > Thanks you very much. > Hans ============================================================================== TOPIC: about java API help under linux http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/64ce8146473a87d0 ============================================================================== == 1 of 2 == Date: Wed, Dec 29 2004 1:25 pm From: "kevin" Hi guys: I wonder if how I can get the function like use jdk-help.chm under windows, I tried to use gnochm to read chm help file, but to be honestly it is so slow and not that functional, so I wonder what is the best way to get the API query and help function under linux when develop java or something else. thanks br kev == 2 of 2 == Date: Wed, Dec 29 2004 5:13 pm From: Sudsy kevin wrote: > Hi guys: > > I wonder if how I can get the function like use jdk-help.chm under > windows, I tried to use gnochm to read chm help file, but to be > honestly it is so slow and not that functional, so I wonder what is the > best way to get the API query and help function under linux when > develop java or something else. Already asked and answered... ============================================================================== TOPIC: field name for jOptionPane when using Eclipse? http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/ecc8b53a68d74225 ============================================================================== == 1 of 1 == Date: Wed, Dec 29 2004 2:52 pm From: Chris Smith ted holden <[EMAIL PROTECTED]> wrote: > Thanks, that does work. I'd still be curious to know how to get a handle on > application variables like the main application frame if there's a way to > do that sort of thing... There is no such thing as "the main application frame" in the general case. However, if you have a reference to any AWT component, you can use SwingUtilities.getWindowAncestor to find the top-level Window that contains it. In some cases (such as applets, for example, when there may not be a Java object to represent the top-level window), this might return null. It might also return something that's not a Frame. JOptionPane doesn't require a Frame, though. It only requires a Component, which can be anything that's contained within the parent Frame. It's been mentioned that you can pass null, but it's best to pass a Component of some kind if you can. Passing null causes awkward moments where there is no focused window after the JOptionPane is dismissed. It's worth mentioning that Eclipse itself uses a non-AWT GUI framework called SWT. SWT is not a generally good idea to use in new code unless it happens to meet some very specific requirements that you have. It's generally an even worse idea, though, to mix SWT and AWT/Swing code if you can avoid it. Some of the GUI-building plugins for Eclipse design in SWT instead of AWT or Swing, and if you're doing that you should avoid JOptionPane. If that's the case, you may not have an AWT component anywhere. (If you insist on mixing AWT and Swing, then just pass null for the parent.) -- www.designacourse.com The Easiest Way To Train Anyone... Anywhere. Chris Smith - Lead Software Developer/Technical Trainer MindIQ Corporation ============================================================================== TOPIC: Is there a Class like HashMap, but... http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/90f6b5fefbb8ee0a ============================================================================== == 1 of 8 == Date: Wed, Dec 29 2004 11:08 pm From: ByteCoder Is there a Class like HashMap, but which only stores the key. Basicly, I want a Class which adds unique objects to it, but which overwrites non-unique objects. TIA, -- ------------- - ByteCoder - ...I see stupid people ------------- Curiosity *Skilled* the cat == 2 of 8 == Date: Wed, Dec 29 2004 11:45 pm From: ByteCoder ByteCoder wrote: > Is there a Class like HashMap, but which only stores the key. > > Basicly, I want a Class which adds unique objects to it, but which > overwrites non-unique objects. > > TIA, I finally found it, it's the HashSet. :) -- ------------- - ByteCoder - ...I see stupid people ------------- Curiosity *Skilled* the cat == 3 of 8 == Date: Wed, Dec 29 2004 5:18 pm From: Sudsy ByteCoder wrote: > Is there a Class like HashMap, but which only stores the key. > > Basicly, I want a Class which adds unique objects to it, but which > overwrites non-unique objects. There's java.util.HashSet but it's backed by a HashMap so why not just use a HashMap and set the value to null? == 4 of 8 == Date: Wed, Dec 29 2004 11:50 pm From: ByteCoder ByteCoder wrote: > ByteCoder wrote: > >> Is there a Class like HashMap, but which only stores the key. >> >> Basicly, I want a Class which adds unique objects to it, but which >> overwrites non-unique objects. >> >> TIA, > > > I finally found it, it's the HashSet. :) > One more thing: Does the HashSet has some sort of get method, so that I don't have to use an Iterator if I just want to get one object? Or wouldn't that be a problem if my HashSet has about 200 elements? -- ------------- - ByteCoder - ...I see stupid people ------------- Curiosity *Skilled* the cat == 5 of 8 == Date: Wed, Dec 29 2004 3:54 pm From: Chris Smith ByteCoder <[EMAIL PROTECTED]> wrote: > One more thing: Does the HashSet has some sort of get method, so that I > don't have to use an Iterator if I just want to get one object? > Or wouldn't that be a problem if my HashSet has about 200 elements? No, it doesn't. There could never be a defined response for such a method, since HashSet doesn't maintain any order for its elements. If you want an arbitrary element, then set.iterator().next() is the easiest way. There should be minimal cost in creating an Iterator, and this cost should not depend in any way on the size of the HashSet. I wouldn't worry about it. -- www.designacourse.com The Easiest Way To Train Anyone... Anywhere. Chris Smith - Lead Software Developer/Technical Trainer MindIQ Corporation == 6 of 8 == Date: Wed, Dec 29 2004 2:55 pm From: ByteCoder Sudsy wrote: > ByteCoder wrote: > >> Is there a Class like HashMap, but which only stores the key. >> >> Basicly, I want a Class which adds unique objects to it, but which >> overwrites non-unique objects. > > > There's java.util.HashSet but it's backed by a HashMap so why not > just use a HashMap and set the value to null? Or set the value to the same object as the key, or would that use too much space (considering the HashMap might have ~200 elements)? My object would have a few (<6) private variables, and a few methods (again, <6). -- ------------- - ByteCoder - ...I see stupid people ------------- Curiosity *Skilled* the cat == 7 of 8 == Date: Wed, Dec 29 2004 2:57 pm From: ByteCoder Chris Smith wrote: > ByteCoder <[EMAIL PROTECTED]> wrote: > >>One more thing: Does the HashSet has some sort of get method, so that I >>don't have to use an Iterator if I just want to get one object? >>Or wouldn't that be a problem if my HashSet has about 200 elements? > > > No, it doesn't. There could never be a defined response for such a > method, since HashSet doesn't maintain any order for its elements. If > you want an arbitrary element, then set.iterator().next() is the easiest > way. > > There should be minimal cost in creating an Iterator, and this cost > should not depend in any way on the size of the HashSet. I wouldn't > worry about it. Thanks. HashSet is still the most-likely solution to my problem. -- ------------- - ByteCoder - ...I see stupid people ------------- Curiosity *Skilled* the cat == 8 of 8 == Date: Wed, Dec 29 2004 2:59 pm From: Chris Smith Sudsy <[EMAIL PROTECTED]> wrote: > There's java.util.HashSet but it's backed by a HashMap so why not > just use a HashMap and set the value to null? Correction: in the current version of the Sun implementation of the Java API, HashSet is backed by a HashMap. That's certainly not specified behavior. One good reason not to use a HashMap and set the value to null is that it seems almost like an intentional effort to obscure the purpose of the code. If you want a set of something, you ought to be using a Set, not a Map. It's beyond me why the implementation of that Set would matter to you, except for performance reasons. I have yet to see any indication that HashSet fails to perform well, or that a different implementation would perform substantially better in any situation at all. -- www.designacourse.com The Easiest Way To Train Anyone... Anywhere. Chris Smith - Lead Software Developer/Technical Trainer MindIQ Corporation ============================================================================== TOPIC: maintain data in tabs in JSP pages http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/f88868e021fdf086 ============================================================================== == 1 of 1 == Date: Wed, Dec 29 2004 2:14 pm From: [EMAIL PROTECTED] I have 4 tabs on the window. When the user click one of the tabs, then it will go to that page. should I have 4 JSP pages in this case? But I also need to maintain the data of each page. For example, the user enter the data in the form in page1, and then click tab2, and go click back tab1, the data the user just entered should still in page1. Then I will keep 4 copies of data objects for the form in session? please advise the best approach. thanks!! ============================================================================== You received this message because you are subscribed to the Google Groups "comp.lang.java.programmer" group. To post to this group, send email to [EMAIL PROTECTED] or visit http://groups-beta.google.com/group/comp.lang.java.programmer To unsubscribe from this group, send email to [EMAIL PROTECTED] To change the way you get mail from this group, visit: http://groups-beta.google.com/group/comp.lang.java.programmer/subscribe To report abuse, send email explaining the problem to [EMAIL PROTECTED] ============================================================================== Google Groups: http://groups-beta.google.com
