comp.lang.java.programmer http://groups-beta.google.com/group/comp.lang.java.programmer [EMAIL PROTECTED]
Today's topics: * GC tuningm, some tips (Re: VM Error - heap memory problem) - 1 messages, 1 author http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/363218dc7986a594 * compressing or encrypting a String - 1 messages, 1 author http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/d28e472c042b2e3a * help on threads/monitor needed - 3 messages, 2 authors http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/cefb56e3aa05046e * Using anchor tags in struts - 5 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 * Symbian or J2ME, which one is the trend? - 1 messages, 1 author http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/727a56c9759c61bb * How to get list of roles for authenticated user? - 2 messages, 2 authors http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/eca88074b3cc9e4 * [jsp]: getProperty - 1 messages, 1 author http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/6230ddcfe0818100 * field name for jOptionPane when using Eclipse? - 2 messages, 2 authors http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/ecc8b53a68d74225 * How too.. ?? - 3 messages, 3 authors http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/fd299b7c69eb3e1a * jdbc question - 3 messages, 3 authors http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/bab6d8d5c6089b91 * Want some extra cash, try this - 1 messages, 1 author http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/b87d538e7162b4b2 * JTable in Applet doesn't receive keypresses under Win2000 (XP is Ok) - 1 messages, 1 author http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/eda43654e347cc2e ============================================================================== TOPIC: GC tuningm, some tips (Re: VM Error - heap memory problem) http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/363218dc7986a594 ============================================================================== == 1 of 1 == Date: Thurs, Dec 30 2004 1:58 pm From: Bjorn Borud [Surendra Singhi <[EMAIL PROTECTED]>] | | There was no problem with the code, it was an incompatibility issue | between code compiled in different version of jvm(i.e. 1.4.05) and | being run using a newer version of jvm(1.4.06). good thing you found the source of the problem. although your problem was an actual bug and not GC tuning, I thought I'd share a tip with you about GC tuning anyway :-). if it were heap sizing issues I would recommend installing and running jvmstat. this is the single most useful tool I've seen for understanding what is going on with your application vs GC and heap parameter tuning. follow the advice in the docs and start tweaking the coarse-grained parameters first. I had a heap sizing problem which was quickly resolved by just looking at the jvmstat GUI (visualgc) while the program was running and adjusting some parameters. also: nothing good will come from running GC manually. check your heap with jvmstat and tune if necessary. most of the time you just need to size things correctly. sometimes you *might* want to choose a different GC algorithm (but most of the time you should leave this untouched). if someone says you should run GC manually, you can safely ignore them. some links: http://java.sun.com/performance/jvmstat/ http://www.unixville.com/~moazam/stories/2004/05/18/visualizingGarbageCollection.html -Bjørn ============================================================================== TOPIC: compressing or encrypting a String http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/d28e472c042b2e3a ============================================================================== == 1 of 1 == Date: Thurs, Dec 30 2004 2:00 pm From: James Kanze Chris Uppal wrote: > Wendy S wrote: >>How often do two Strings compare as equal when they're >>actually not? > [I'm assuming you mean, "how often to they have equal hashes > when they're not equal?"] > If you are producing 32-bit hash codes, and if your hashing > algorithms produces more-or-less random values, then you'd > expect to find at least 1 pair of strings with the same hash > if you have at least 2^16 input strings. 65,000 files isn't > really /that/ many, so I wouldn't recommend using a 32-bit > hash for this kind of purpose unless you know that your > application is going to be handling a lot less than 65K files. Note that 1) Java's hash codes are actually only 31 bits (no unsigned 32 bit type), and 2) the last time I looked, the Java hash code was not particularly good for certain types of strings -- the multiplier is too small. > Also that is on the assumption that String.hash() is of > reasonable quality. It doesn't look spectacularly good to me > (though I haven't attempted to validate it). It is fairly trivial to create test cases where it doesn't work well -- say all possible two character strings. Whether this is a problem with real strings depends on what you are doing. > In any case, if you want your hashes to be reliable over a > release of a new JVM implementation, then you can't base your > file names on the String.hash() function since it is possible > that the next version of the JVM will use a different hash > method (it has already changed once, so maybe it'll change > again). The original version was a disaster. The current version is a linear congruent hash using a Mersenne prime as a multiplier -- in my experience, these generally make pretty good hash functions. On the other hand, the multiplier is small, which if nothing else means that you won't get large numbers from very short strings. > I think you'd be better off using a hash function that: > a) produces a lot more than 32 bits of output > b) is defined independently of the JVM implementation. Agreed on both counts. > One excellent source of such hashes is to use a crypto hash > like SHA-1 (160 bit?) or MD5 (128 bit). I've never had to do > that in Java, but I presume one would start with an instance > of MessageDigest. CRC codes are another good source -- done correctly, they can be a lot faster than MD5. (I've never implemented SHA-1.) > However the actual crypto-graphic quality is unimportant here, > so you might find it easier and quicker to code your own > 64-bit (say) hash function. Here's what I would try first if > I needed to do this, it's translated directly from 'C' so > it'll probably not compile... > /** > * a String hash implemented as a perturbed 64-bit linear congruential > pseudo-random > * number generator. > */ > long > longLinearCongruentialHash(String input) > { > long hash = 0L; > for (int i = 0; i < input.length(); i++) > { > hash += input.charAt(i); > hash *= 6364136223846793005L; > } > return hash; > } I'd have a look at http://www.isthe.com/chongo/tech/comp/fnv/. As far as I know, I invented the use of a Mersenne prime for the multiplicator, but I currently use FNV whenever I need a hash code -- it's been more or less proven good. About the only time I might use something else would be on a machine where multiplication is extremely slow. What made me look at Mersenne primes in the first place is that the multiplication can be implemented by means of a single shift and a subtraction -- on an 8086, this made a whale of a difference, but on a modern processor? Note that getting it both correct and rapid without unsigned arithmetic isn't necessarily trivial. On the other hand, it's possible (or even probable?) that the errors introduced by Java's signedness don't really make it that much worse. -- James Kanze home: www.gabi-soft.fr Conseils en informatique orientée objet/ Beratung in objektorientierter Datenverarbeitung 9 pl. Pierre Sémard, 78210 St.-Cyr-l'École, France +33 (0)1 30 23 00 34 ============================================================================== TOPIC: help on threads/monitor needed http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/cefb56e3aa05046e ============================================================================== == 1 of 3 == Date: Thurs, Dec 30 2004 2:21 pm From: ByteCoder [EMAIL PROTECTED] wrote: > I have not made it clear enough in my first posting, that I don't want > to wait, say 500 ms, in between tasks. My reason for using threads is > to make the application save and to do a fast initialization which does > not take, say 10 * 500 ms. > > Ideally the GUI should not interfere (only interrupt, but not stop) > taking data from RS232, even if some user heavily uses it. So my vision > is to use one lock which I can use for all threads including AWT and > swing threads. Is this possible? Why would you want more than one thread that manages the RS232? Why would more than one thread be necessary when there is only one RS232 device/input? Just start one thread from your swing application that initializes the communication and read data from it from your swing application. You could give the communications thread a textfield or something like that when it starts and whenever the communications thread reads a line it adds that line to the textfield. -- ------------- - ByteCoder - ...I see stupid people ------------- Curiosity *Skilled* the cat == 2 of 3 == Date: Thurs, Dec 30 2004 2:26 pm From: ByteCoder ByteCoder wrote: [...] > You could give the communications thread a textfield or something like > that when it starts and whenever the communications thread reads a line > it adds that line to the textfield. > Actually, that's not a good idea. Like I said before, just let a thread execute a public synchronized method in the swing app. That won't affect the performance of your app in any noticable way. -- ------------- - ByteCoder - ...I see stupid people ------------- Curiosity *Skilled* the cat == 3 of 3 == Date: Thurs, Dec 30 2004 8:17 am From: [EMAIL PROTECTED] Thanks again ByteCoder! The reason for using different classes (which are 'Runnable') is to handle different Strings comming/going to RS232, as I told before. The structure of the Strings are quite different, which makes it too difficult to handle in one serialEvent method. Could somebody answer to my questions, which I guess are elemantary to all thread freaks out there: Once again: Can I use synchronized (applied to methods) applied in several classes, using one lock (my boolean parameter which I set true and false in the synchronized methods)? My access to the lock would go through the argument passed in the constuctor, to make my lock parameter 'visible'. snippet: public class T1 implements ... { ... private SerialConnection connection; //constructor public T1(SerialConnection connection){ this.connection = connection; } public synchronized void serialEvent(SerialPortEvent e) { ... connection.threadActive = false; // is this possible? } }//class In the calss SerialConnection I have declared the attribute public volatile boolean threadActive; // I use this as lock which is set true in another synchronized method before entering the serialEvent method above Frank ============================================================================== TOPIC: Using anchor tags in struts http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/74fff906636dadfd ============================================================================== == 1 of 5 == Date: Thurs, Dec 30 2004 5:30 am From: [EMAIL PROTECTED] Ah, Wendy - a breath of fresh air. I had thought about a similar solution yesterday that I will try today. I think you have the right idea though and it deserves a wider audience. In investigating this phenomenon on Sun's site and elsewhere, it remains unresolved even though what you are presenting is precisely what the doctor ordered. Thanks - excellent thinking. == 2 of 5 == Date: Thurs, Dec 30 2004 9:08 am From: Sudsy Wendy S wrote: <snip> > Are you opposed to a bit of JavaScript? I have a very long page in which I > allow people to hide and show sections. Hiding or showing causes a round > trip to the server, and I need to return them to the same section they were > looking at. In the Action, I set: > request.setAttribute( "anchor", "nameOfAnchor"); > > Then at the bottom of the JSP (so it won't execute until the page has > finished loading) I have: > <c:if test="${anchor ne null}"> > <script> > document.location = "#<c:out value="${anchor}"/>"; > </script> > </c:if> <snip> I've got to hand it to you, Wendy: that's a slick solution! It won't work if JavaScript is disabled/unavailable but it should certainly work in the majority of cases. Nice job of "thinking outside the box". == 3 of 5 == Date: Thurs, Dec 30 2004 8:52 am From: "Wendy S" <[EMAIL PROTECTED]> wrote: > I think you have the right idea though and it deserves a wider > audience. In investigating this phenomenon on Sun's site and > elsewhere, it remains unresolved even though what you are > presenting is precisely what the doctor ordered. Well, feel free to re-post it wherever you think it will help! Thanks to you and Sudsy for the compliments. :) -- Wendy Smoak == 4 of 5 == Date: Thurs, Dec 30 2004 8:06 am From: [EMAIL PROTECTED] Fellow investigators - here's a variation on Wendy's theme that suits my purposes slightly better. I'll share it in the event that it's of interest to others. What I did is the following: In my loginFormBean, I have the following methods; public ActionErrors validate( ActionMapping mapping, HttpServletRequest request) { ActionErrors errors = new ActionErrors(); // Validate the fields in your form, adding // adding each error to this.errors as found, e.g. checkEmpty(getDestination(), errors, "destination_missing"); checkEmpty(getTrustedUsername(), errors, "username_missing"); checkEmpty(getTrustedPassword(), errors, "password_missing"); // This next error is where I test the javascript // After all, we only want to go to this anchor when I have an error or information // to give the user checkEmpty("",errors, "test"); // if ((field == null) || (field.length() == 0)) { // errors.add("field", new org.apache.struts.action.ActionError("error.field.required")); // } return errors; } private void checkEmpty(String param, ActionErrors errs, String msg) { if (param == null || param.trim().length() == 0) { errs.add(msg, new org.apache.struts.action.ActionError(msg)); } } Then in my properties file I added; # Optional header and footer for <errors/> tag. #errors.header=<ul> #errors.footer=</ul> destination_missing=<li>You forgot to mention which platform this login applies to. username_missing=<li>What is your username? password_missing=<li>Your password is? test=<script>document.location = "#aaa";</script> Notice my message is javascript that executes on demand. My jsp page looks something like: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html:HTML> <HEAD> <%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %> <%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %> <%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1" %> <META http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <META name="GENERATOR" content="IBM WebSphere Studio"> <META http-equiv="Content-Style-Type" content="text/css"> <meta http-equiv="Pragma" content="no-cache"> <LINK href="theme/Master.css" rel="stylesheet" type="text/css"> <TITLE>SecurityPropertiesLogon.jsp</TITLE> </HEAD> <BODY > // snip <p><html:form action="/login.do"><b> <font face="Verdana">UserName: </font></b> <input type="TrustedUsername" name="trustedUsername"/> <br><b><font face="Verdana">Password: </font></b> <input type="TrustedPassword" name="trustedPassword" /> //snip <html:submit>XXX</html:submit> // snip </html:form> <a NAME="aaa"> </a> <%@ include file="InfoAndErrors.jspf"%> </BODY> </html:HTML> Then InfoAndErrors looks like: <%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %> <%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %> <br><b><font color="#CCCCCC">Information, errors, and further instructions:</font></b><html:errors/> Now, what I like about this is that the anchor is executed only when the code is instrumented to do so. This means I can use the Struts error facility for realtime debugging purposes by further tweaking the code a bit and employing the Struts <html:errors> facility to kick out debugging messages as instrumented. I'm using WSAD 5.1.x and this seems to work fine in preliminary tests I'm doing. Your mileage may vary. == 5 of 5 == Date: Thurs, Dec 30 2004 8:23 am From: [EMAIL PROTECTED] Oh, one last technical note. In my example I was just playing around with multiple error messages. On a true login screen a better practice is not to tell the person attempting a login exactly which input is incorrect. Finally, thanks to everyone who responded - I think this is one of those tricky asides in Struts that needed clarification - our good deed for the day. ============================================================================== TOPIC: [JSP] Help with Design decision http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/7906830f6d90dea6 ============================================================================== == 1 of 1 == Date: Thurs, Dec 30 2004 7:36 am From: "Ryan Stewart" "Marcus Reiter" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] >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. > Is this the same assignment you were asking about in the other post? You were supposed to do this with only jsp tags? > 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. > Better to go OO. One possiiblity: public class User { String name; TestPanel tests; } public class TestPanel { Map tests; // key=Test, value=Boolean indicating selected } public class Test { String name; } This is just bare bones obviously. > 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? > For performance, it's almost always better to only do what updates are necessary. For ease of coding, it's almost always better to just rewrite everything. ============================================================================== TOPIC: Symbian or J2ME, which one is the trend? http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/727a56c9759c61bb ============================================================================== == 1 of 1 == Date: Thurs, Dec 30 2004 1:37 pm From: Andrew McDonagh Maxim Kasimov wrote: > [EMAIL PROTECTED] wrote: > >> hi, >> >> For mobile software development, J2ME is more portable and widely >> supported; Symbian, with the largest mobile OS market share, is more >> feature-rich and powerful. They each has pro's and con's. >> >> I wander nowadays which one is the trend...are more and more people >> moving to J2ME platform for development of mobile software, or there >> are still a lot of people firmly sticking to Symbian native >> development. >> >> Thanks very much. >> > > IMHO it does not matter which platform have more features than another. > Matters only the content you can make - if for game or application > implementing > quite enough features of midp1.0 you should not use Symbian native > development. > Mobile operators favour Java over symbian - so much so that our symbian apps development has stopped and has been ported to Java. Its because there's actually far more Java enabled phones than Symbian. ============================================================================== TOPIC: How to get list of roles for authenticated user? http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/eca88074b3cc9e4 ============================================================================== == 1 of 2 == Date: Thurs, Dec 30 2004 5:41 am From: "Techie" Thought HttpRequest would have something like getUserRoles() or something, but no go. What gives w/ the Javax API? Why no getUsesrRoles()? What am I missing? How do I get a list of roles that an authenticated user (Principal, whatever) has access to? Danke. == 2 of 2 == Date: Thurs, Dec 30 2004 10:29 am From: Sudsy Techie wrote: > Thought HttpRequest would have something like getUserRoles() or > something, but no go. What gives w/ the Javax API? Why no > getUsesrRoles()? What am I missing? How do I get a list of roles that > an authenticated user (Principal, whatever) has access to? see javax.servlet.http.HttpServletRequest#isUserInRole and javax.servlet.http.HttpServletRequest#getUserPrincipal. ============================================================================== TOPIC: [jsp]: getProperty http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/6230ddcfe0818100 ============================================================================== == 1 of 1 == Date: Thurs, Dec 30 2004 7:42 am From: "Ryan Stewart" "Marcus Reiter" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > I can't find a way, but the prof. said we should put the values coming > from > the > database into a bean and then to retrieve them from there. > But the problem is that the database is full of several entries and > so I had to put each entry into a bean and each bean into a vector. > Now I don't see a way of how to print out each value by using the > getProperty / setProperty Tag. > > Even if the Vector would contain plain Strings instead of Beans - > then it would print out the values without html formating - > of course I could even include that into my vector - > but then html code and data is mixed and that's even worse imho! > I had a sneaky idea: public class InfoBean { public InfoBean() { // Database calls to populate this bean with first available data } public String getProperty1 { return something; } public String getProperty2 { return somethingElse; } public String getProperty3 { String returnValue = somethingElsesBrother; // Database calls to populate this same bean with the next data return returnValue; } } Then you can just repeatedly use getProperty on the properties, and it will automatically reset after the last one. The only problem then is knowing how many times to cycle through. As an aside, I would never do something like this in general practice. This is a case of using questionable code to meet questionable requirements. ============================================================================== TOPIC: field name for jOptionPane when using Eclipse? http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/ecc8b53a68d74225 ============================================================================== == 1 of 2 == Date: Thurs, Dec 30 2004 8:59 am From: Sudsy ted holden wrote: <snip> > Like I say, given the setup described and trying to use AWT, the layout > managers other than null simply do not appear to work or do anything > terribly useful. In fact, I would describe the behavior of the gui tool > while trying to use AWT and the flowlayout for instance, as pathalogical. > Widgets and/or panels which I try to place on the framework go to the > center top in minimized form and changing the "preferred size" produces > pathological results. I suppose that I just don't understand your problem with layout managers. I don't eve find GridBagLayout too onerous to use, for example. Then again, I used to develop applications using X11/Motif so it's not a huge leap for me... But if you come from a M$ world were everything is drag-and-drop in a GUI builder then I imagine that it would take time to obtain familiarity with the various layout manager. But just out of curiousity, how are different screen resolutions handled by the M$ tools? == 2 of 2 == Date: Thurs, Dec 30 2004 8:20 am From: Chris Smith ted holden <[EMAIL PROTECTED]> wrote: > I'm assuming that the server for this app will run under linux and that > 99.999% of all clients will be running windows. Based on what I've seen, > I'd rather deal with any problems which come up than try to deal with java > layouts. Do what you like. You should know, though, that use of layout managers for Java applications is universally considered a bare minimum requirement for writing professional quality code. Should you ever end up writing code for someone else, they are almost certain to insist upon it (unless they just aren't technical, in which case you could get away with a shoddy job, I suppose). > In fact I've stitched Tcl/Tk guis together by hand using the > layout system Tk provides and I don't remember there being any unholy level > of grief doing so. Speaking of coding stuff by hand, it's worth mentioning that a fair number of people (myself included, actually) hold the belief that it's actually easier to build Java GUIs by hand rather than use a visual GUI designer. The reason is that layout managers actually give you a much higher-level view of the GUI layout. So while a GUI builder is necessary, for example, in Visual Basic to prevent specifying pixel coordinates for everything, they can just get in the way in Java. Before that's true, though, you'd need to learn how all the major layout managers actually work. I don't know, at this point, if your problems are with Ecplise VE, or with the layout managers you're trying to use. I can tell you that I tried to use Eclipse VE once about six months ago. After an extremely frustrating afternoon, I went back to coding GUIs by hand. I might wait until the project is more mature, and then try again. -- www.designacourse.com The Easiest Way To Train Anyone... Anywhere. Chris Smith - Lead Software Developer/Technical Trainer MindIQ Corporation ============================================================================== TOPIC: How too.. ?? http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/fd299b7c69eb3e1a ============================================================================== == 1 of 3 == Date: Thurs, Dec 30 2004 3:05 pm From: "H. Sommers" The picture will not appear, but why?????????? When I use a simple applet, it works. ------------------------------------------------------------------------------------------------------------------------- package test; public class TestClass { public TestClass() { } public static void main(String[] args) { TestClass testClass = new TestClass(); TestFrame test = new TestFrame(); test.show(); } } ----------------------------------------------------------------------------------------------------------------------------- package test; import java.awt.*; import javax.swing.*; public class TestFrame extends JFrame { JButton jButton1 = new JButton(); public TestFrame() { try { jbInit(); } catch(Exception e) { e.printStackTrace(); } } private void jbInit() throws Exception { jButton1.setText("jButton1"); jButton1.setBounds(new Rectangle(67, 37, 182, 114)); this.getContentPane().setLayout(null); this.setSize(new Dimension(300, 300)); this.getContentPane().add(jButton1, null); } // ???????????????????????????? // ???????????????????????????? // ???????????????????????????? private void picture() { ImageIcon pic = new ImageIcon("images/duke.gif"); jButton1.setIcon(pic); } } == 2 of 3 == Date: Thurs, Dec 30 2004 8:06 am From: "Ryan Stewart" "H. Sommers" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > The picture will not appear, but why?????????? > When I use a simple applet, it works. [...] Please do not multipost. == 3 of 3 == Date: Thurs, Dec 30 2004 2:15 pm From: Andrew Thompson On Thu, 30 Dec 2004 15:05:38 +0100, H. Sommers wrote: > The picture will not appear, but why?????????? This message will appear on a number of groups.. <http://www.physci.org/codes/javafaq.jsp#xpost> Whereas the answer.. will appear on only one message you posted. -- Andrew Thompson http://www.PhySci.org/codes/ Web & IT Help http://www.PhySci.org/ Open-source software suite http://www.1point1C.org/ Science & Technology http://www.LensEscapes.com/ Images that escape the mundane ============================================================================== TOPIC: jdbc question http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/bab6d8d5c6089b91 ============================================================================== == 1 of 3 == Date: Thurs, Dec 30 2004 9:05 am From: Sudsy Thomas Kellerer wrote: <snip> > Why not do it the other way round? Update the row first, then check the > number of affected rows (which is returned by the executeUpdate() method > and is DBMS indepdent). If zero records were affected then the record is > not there and you can insert it. Thus you do not need to rely on error > codes for specific DBMS when catching an error during the insert. I was wondering if/when someone would make this suggestion! The problem is, as others have mentioned, a matter of timing. Suppose you try an update and it fails. Between that point in time and the time you try an insert, another database client inserts a record with the same primary key. So now your insert fails and you have to fallback to performing the update again. KISS and perform an insert; iff it fails then try to update. == 2 of 3 == Date: Thurs, Dec 30 2004 3:58 pm From: "Virgil Green" Mark Thornton wrote: > Chris Uppal wrote: >> Mark Thornton wrote: >> >> >>> 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. >> >> >> Or, more accuately, /not/ work on most databases ;-) It leaves a >> hole where another app could insert the to-be-duplicate row into the >> DB between your query and your insert. > > Not true --- it will work wherever transactions are properly > supported. You simply have to turn off the auto commit and commit the > transaction yourself after doing the update(s). Admittedly you may > still have to watch for serialization exceptions (deadlock), but that > should be rare. I'm not familiar with any database that can maintain the integrity of a transaction by guaranteeing that a record continues to *not* exist throughout the transaction. Prevent deletion and updates to an existing record outside the transaction? Yes. Ensure that a record that didn't exist at the beginning of the tranaction is only created within the transaction? Not to my knowledge. Which ones do this? - Virgil == 3 of 3 == Date: Thurs, Dec 30 2004 8:22 am From: Thomas Kellerer Sudsy wrote on 30.12.2004 15:05: >> Why not do it the other way round? Update the row first, then check >> the number of affected rows (which is returned by the executeUpdate() >> method and is DBMS indepdent). If zero records were affected then the >> record is not there and you can insert it. Thus you do not need to >> rely on error codes for specific DBMS when catching an error during >> the insert. > > > I was wondering if/when someone would make this suggestion! The problem > is, as others have mentioned, a matter of timing. Suppose you try an > update and it fails. Between that point in time and the time you try an > insert, another database client inserts a record with the same primary > key. So now your insert fails and you have to fallback to performing > the update again. KISS and perform an insert; iff it fails then try to > update. Without specific requirements there is no way telling which version is better. If this is e.g. a data load that is performed during the night, the the solution is absolutely valid. If this is a use case with highly partioned data (each user edits different records) then it's valid as well, if the situation is a highly dynamic entry system where the situation that you sketched is very likely to happen, then obviously this is not a good idea. On the other hand: if you expect more updates then inserts to be successful, the overall performance would be *much* better this way because the index lookup for the primary key is only needed once for the update but twice for the inser/update combo. I was simply offering a different solution. If it's feasible for the situation of the OP is up to him (and he did not give information to us in order to judge that) Thomas ============================================================================== TOPIC: Want some extra cash, try this http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/b87d538e7162b4b2 ============================================================================== == 1 of 1 == Date: Thurs, Dec 30 2004 7:14 am From: [EMAIL PROTECTED] want some extra cash, try this THIS REALLY CAN MAKE YOU EASY MONEY!! A little while back, I was on my computer having a grand old time, just like you are now and came across an article similar to this that said you could make thousands dollars within weeks with only an initial investment of $6.00! So I thought, "Yeah, right, this must be a scam", but like most of us, I was curious, so I kept reading. Anyway, it said that you send $1.00 to each of the 6 names and address stated in the article. You then place your own name and address in the bottom of the list at #6, and post the article in at least 200 newsgroups. No catch, that was it. So after thinking it over, and talking to few people first, I thought about trying it. I figured what have I got to lose except 6 stamps and $6.00, right? Like most of us I was a little skeptical and a little worried about the legal aspects of it all, So I checked it out with the U.S. Post Office (1- 800-725-2161) and they confirmed that it is indeed legal! Then I invested the measly $6.00. Well GUESS WHAT!!?. Within 7 days, I started getting money in the mail! I was shocked! I figured it would end soon, but the money just kept coming in. In my first week, I made about $25.00. By the end second week I had made a total over $1,000.00! In the third week I had over $10, 000.00 and it's still growing. Its Certainly worth $6.00, and 6 stamps, I have spent more than that on the lottery!! Let me tell you how this works and most importantly, why it works?. STEP 1: Get 6 separate pieces of paper and write the following on each piece of paper "PLEASE PUT ME ON YOUR MAILING LIST." Now get 6 US $1.00 bills and place ONE inside EACH of the 6 pieces of paper so the bill will not be seen through the envelope to prevent thievery. Next, place one paper in each stating the above phrase, your name and address, and a $1.00 bill. What you are doing is creating a service by this. THIS IS ABSOLUTELY LEGAL! Mail the 6 envelopes to the following addresses: #1) Jason Barone P.O. Box 1015 Glen Burnie, MD 21060-1015 #2) Jonathon Markwood 3308 Birdsong Way Birmingham, AL 35242 #3) Eben Mcgee 1876 #C Locust, Las Cruces, NM 88001 #4) Ricky DeMaio 471 McCutcheon rd, Hudson WI 54016 #5) P. Ortner 29 Briarlee Dr. Tonawanda, NY 14150 #6) O. Humphrey 8452 E. Louise Dr, Tucson, AZ 85730 STEP 2: Now take the #1 name off the list that you see above, move the other names up and add YOUR Name as number 6 on the list. STEP 3: Change anything you need to, but try to keep this article as close to original as possible. Now, post your amended article to at least 200 newsgroups, message board. All you need is 200, but remember, the more you post, the more money you make!---- Just copy this message, paste it in Word or Notepad, find message boards like this and paste away. Congratulations? THAT'S IT! All you have to do is jump to different newsgroups and post away, after you get the hang of it, and it will take about 30 seconds for each newsgroup! * REMEMBER, THE MORE NEWSGROUPS OR MESSAGE BOARD YOU POST IN, THE MORE MONEY YOU EILL MAKE!! BUT YOU HAVE TO POST A MINIMUM OF 200* That's it! You will begin receiving money from around the world within days! ============================================================================== TOPIC: JTable in Applet doesn't receive keypresses under Win2000 (XP is Ok) http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/eda43654e347cc2e ============================================================================== == 1 of 1 == Date: Thurs, Dec 30 2004 8:16 am From: "Dag Sunde" "Ann" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > > "Dag Sunde" <[EMAIL PROTECTED]> wrote in message > news:[EMAIL PROTECTED] > > I have a (rather large as applets go) Applet > > running in IE 6.0 with JRE 1.4.2 (Plugin) > > > > Under Win XP, my JTable receives keypresses > > (goes into, and out of edit cell mode, arrow > > keys moves from cell to cell, etc...) ie. > > everything is working normally. > > > > But on every Win2000 box (Still IE 6.0/JRE 1.4.2) > > It doesn't receive any form of keyboard activity. > > No Arrow keys,no nothing... > > > > If I doubleclick on one of the cells with my mouse, > > the cell changes to The Celleditor, and the cursor > > blinks for input as normal, but no response when I > > try to type anything. > > > > It is just like the Whole keyboard have been disabled > > as long as the Applet have focus. > > > > I'm not able to reproduce the problem in a smaller > > SSCCE.... > > > > TIA... > > Maybe the win2000 box is 10-15 times slower than the xp box > and you didn't wait long enough. > Unfortunately, no... Tested on 15 different (fast & slow) boxes... The results are consistent: JRE 1.4.2 /IE 6.0 5 x WIN NT4: Works always 5 x Win2000: Never works 5 x Win XP : Works Always ??? I'm lost! -- Dag. ============================================================================== 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
