comp.lang.java.programmer http://groups-beta.google.com/group/comp.lang.java.programmer [EMAIL PROTECTED]
Today's topics: * Locale question - 1 messages, 1 author http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/54f1e8452a7c830 * sort method for a 2D object array? - 1 messages, 1 author http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/aa57c8d4fc850caf * How to change 3 to "003" - 3 messages, 3 authors http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/4f04fef73a25ccc0 * Reading HTML contents from the server - 2 messages, 2 authors http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/a2f868e582b49802 * Connection Pooling - c3p0 - Tomcat. - 2 messages, 2 authors http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/8bdefe9f4a95f2fb * db connections - 2 messages, 2 authors http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/9796781dceede8f6 * Java regexp help - 1 messages, 1 author http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/be3143a676a4bc8f * TOMCAT/MYSQL/JSP - 1 messages, 1 author http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/6cfdfa12d76632b1 ============================================================================== TOPIC: Locale question http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/54f1e8452a7c830 ============================================================================== == 1 of 1 == Date: Fri, Dec 17 2004 11:57 pm From: "hilz" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > So you have no keys in the text files to identify each message? > No, I don't have a key. Each of those files contain a long paragraph, and there is no key since it is just a paragraph of text. anyway, i just figured out that i can get the two letters of the language by calling Locale.getLanguage() so i append it to the file name before reading it, and it worked. thank you for trying though. thanks hilz ============================================================================== TOPIC: sort method for a 2D object array? http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/aa57c8d4fc850caf ============================================================================== == 1 of 1 == Date: Sat, Dec 18 2004 5:11 am From: Patricia Shanahan Chris Smith wrote: > Tony Morris <[EMAIL PROTECTED]> wrote: > >>>Remember that a so- >>>called "two-dimensional array" is really nothing but an array whose >>>elements are arrays. >> >>Not quite. >>A 2-dimensional array is one that has 2 dimensions e.g. in C#, a int[,] is a >>2-dimensional array; and in COBOL, a TABLE is a 2-dimensional array. >> >>Java has no 2 dimensional arrays (despites false claims, even by the JLS >>itself); it only has arrays of arbitrary type - they are not synonymous. > > > I'm not sure what distinction you're trying to make. As near as I can > tell, what you said is exactly identical to what I said. Yet you say > you don't agree with me. Can you clarify? > Your comment could be interpreted in either of two ways: 1. Any so-called 2-D array, in any language, is nothing but an array whose elements are arrays. 2. What is called a 2-D array in Java is nothing but an array whose elements are arrays. Tony's comment rebuts #1 but agrees with #2. Patricia ============================================================================== TOPIC: How to change 3 to "003" http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/4f04fef73a25ccc0 ============================================================================== == 1 of 3 == Date: Sat, Dec 18 2004 5:20 am From: fishfry How do I convert an int to a 3 (or n) -digit string? I found a couple of third-party implementations of sprintf(), but I was wondering what's the officially correct way to do this. == 2 of 3 == Date: Sat, Dec 18 2004 2:48 am From: IchBin fishfry wrote: > How do I convert an int to a 3 (or n) -digit string? I found a couple of > third-party implementations of sprintf(), but I was wondering what's the > officially correct way to do this. Try looking at 'java.text.DecimalFormat' -- Thanks in Advance... IchBin __________________________________________________________________________ 'The meeting of two personalities is like the contact of two chemical substances: if there is any reaction, both are transformed.' - Carl Gustav Jung, (1875-1961), psychiatrist and psychologist == 3 of 3 == Date: Sat, Dec 18 2004 8:01 am From: "pet0etie" "fishfry" <[EMAIL PROTECTED]> schreef in bericht news:[EMAIL PROTECTED] > How do I convert an int to a 3 (or n) -digit string? I found a couple of > third-party implementations of sprintf(), but I was wondering what's the > officially correct way to do this. > hello, this should work ... but you can always search google on examples of the use of "DecimalFormat" greetz, pet0etie /\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\ /\/\/\/\/\/\/\ public class someClass { // number of digits to show (3 in tour example but easy to modify) private int numDigits = 3; public someClass (int value) { System.out.print("Your original value " + value + " becomes : " + formatValue(value)); } private String formatValue() { private DecimalFormat myFormat = createFormat(numDigits); return myFormat.format(Value); } private DecimalFormat createFormat(int numDigits){ // Create a String that is all 0's, and the length is numDigits. StringBuffer zeros = new StringBuffer(); for (int digit = 1; digit <= numDigits; digit++) { zeros.append("0"); } // Now use that to create a DecimalFormat object. return new DecimalFormat(zeros); } } ============================================================================== TOPIC: Reading HTML contents from the server http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/a2f868e582b49802 ============================================================================== == 1 of 2 == Date: Fri, Dec 17 2004 9:22 pm From: "milkyway" Thank you for responding ;-) I have created cells with the opposite command in Javascript DOM: for iteration = 1 to 999 cell.setAttribute('name', 'Cell' + iteration); end Now on the server side, I am trying to get the value on the server side with something like for i = 1 to 999 value = getvalue of ('cell' + i); <------- end The arrow is what I need now. How to get avalue like this out on the server side. Any ideas? Kindest Regards. Dag Sunde wrote: > "milkyway" <[EMAIL PROTECTED]> wrote in message > news:[EMAIL PROTECTED] > > Hello all, > > > > Is this possible > > 1. Create a table in HTML > > 2. Through javascript add and delete items to the table > > (have already done this) > > 3. Hit the save button and pass the contents of the table to the > > server. > > > > Are there any examples out there where the table contents are being > > passed to the server? > > > > How can one do this? I am basically looking to pass such contents to a > > bean (i.e. 1 'get' statement would fetch all of the items in the HTML > > table). > > > > This is really a JavaScript question...: > > Just as you put the values into the table cells with JavaScript, > write a JavaScript function to extract the values from the table > cells and build a (ie. semicolon/Cr separated) string from them. > document.getElementById("cellId_N"); > > Now put this string into a hidden form-field, and submit the form > .form.doSubmit(); > > -- > Dag. == 2 of 2 == Date: Sat, Dec 18 2004 12:36 am From: "Hal Rosser" "milkyway" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > Thank you for responding ;-) > > I have created cells with the opposite command in Javascript DOM: > > for iteration = 1 to 999 > cell.setAttribute('name', 'Cell' + iteration); > end > > Now on the server side, I am trying to get the value on the server side > with something like > > for i = 1 to 999 > value = getvalue of ('cell' + i); <------- > end > > > The arrow is what I need now. How to get avalue like this out on the > server side. > Dag gave you the answer. you can put the data in a form by using hidden form fields then submit the form - BTW - JavaScript is not Java --- Outgoing mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.818 / Virus Database: 556 - Release Date: 12/17/2004 ============================================================================== TOPIC: Connection Pooling - c3p0 - Tomcat. http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/8bdefe9f4a95f2fb ============================================================================== == 1 of 2 == Date: Sat, Dec 18 2004 1:47 pm From: Rico On Fri, 17 Dec 2004 21:33:05 -0500, Sudsy wrote: > The whole point is that you /don't/ create a new pooled DataSource > every time. All you do is obtain a reference to the DataSource and > invoke getConnection on the object. Precisely. I was thinking that something from the library needs to remain 'alive'. I would understand that what Chris described as the 'ideal' way of making use of the container's context to lookup the DataSource wouldn't create a new pooled DataSource every time. But it seems to me that in the 1st, non-ideal, case of "new ComboPooledDataSource( )" hardcoded in the WEB-INF/classes/misc/Util.class, we're creating a new pooled DataSource every time. It even goes out of scope upon returning from the method call, doesn't it? Which might explain the ResourceClosedException that was thrown every now and then in this non-ideal case... I've found an article that says that even the lookup is expensive and recommends performing the lookup in HttpServlet's init() and keeping the reference to DataSource around somehow. Any thoughts on the expensiveness mentioned? http://www.javaworld.com/javaworld/jw-06-2004/jw-0628-performance.html > The DataSource manages a pool of connections and simply returns one > which is currently unused. It's cheap because you don't create a new > connection This much is clear. What happens in the case of using "new ComboPooledDataSource( )" explicitly? Isn't that a new DataSource created? Thanks. Rico. == 2 of 2 == Date: Sat, Dec 18 2004 1:32 am From: Sudsy Rico wrote: <snip> > I've found an article that says that even the lookup is expensive and > recommends performing the lookup in HttpServlet's init() and keeping the > reference to DataSource around somehow. Any thoughts on the expensiveness > mentioned? We're getting some cross-over with another thread discussing connection pools. In fact I just responded to that thread with a quote from the java.sql.PooledConnection javadocs. Your information is quite correct: JNDI lookups are expensive and you should make every effort to perform them as rarely as practicable. In the case of Struts applications, I store the Home references in application scope. You just have to implement a recovery mechanism so that naming system outages don't permanently (until restart) dis- able your application. > This much is clear. What happens in the case of using "new > ComboPooledDataSource( )" explicitly? Isn't that a new DataSource created? You're creating a new object instance but the behaviour "under the covers" might be to return a Facade. You could, in fact, be accessing a Singleton when you invoke methods on the object. It's impossible to tell without seeing the source code. While I don't have access to my source at this moment, I seem to recall performing the initial lookup on the ConnectionPoolDataSource and just keeping it around. ============================================================================== TOPIC: db connections http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/9796781dceede8f6 ============================================================================== == 1 of 2 == Date: Fri, Dec 17 2004 11:51 pm From: "Ryan Stewart" "Sudsy" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > Big Jim wrote: >> Guys, >> >> In a a stateful session bean I'm looking up a data source that wraps a >> connection pool and using it to retrieve a connection. >> How do I return the connection to the pool when I'm done? Is conn.close() >> the right thing to do here? > > Absoutely right! Closing it releases it back to the pool. > Are you sure that's universal? I may be wrong, but I thought I'd read about pooling implementations in which you'd call something like connection.release() or even ConnectionPool.dump(connection) == 2 of 2 == Date: Sat, Dec 18 2004 1:05 am From: Sudsy Ryan Stewart wrote: > "Sudsy" <[EMAIL PROTECTED]> wrote in message > news:[EMAIL PROTECTED] > >>Big Jim wrote: >> >>>Guys, >>> >>>In a a stateful session bean I'm looking up a data source that wraps a >>>connection pool and using it to retrieve a connection. >>>How do I return the connection to the pool when I'm done? Is conn.close() >>>the right thing to do here? >> >>Absoutely right! Closing it releases it back to the pool. >> > > Are you sure that's universal? I may be wrong, but I thought I'd read about > pooling implementations in which you'd call something like > connection.release() or even ConnectionPool.dump(connection) A quick trip to the javadocs finds this in javax.sql.PooledConnection: "When an application closes a connection, it calls the Connection method close. When connection pooling is being done, the connection pool manager is notified because it has registered itself as a ConnectionEventListener object using the ConnectionPool method addConnectionEventListener. The connection pool manager deactivates the handle to the PooledConnection object and returns the PooledConnection object to the pool of connections so that it can be used again. Thus, when an application closes its connection, the underlying physical connection is recycled rather than being closed." Do all implementations faithfully implement this? Possibly not, if you've heard about situations where non-standard methods are required. This is just the way it's /supposed/ to work. Fair enough? ============================================================================== TOPIC: Java regexp help http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/be3143a676a4bc8f ============================================================================== == 1 of 1 == Date: Fri, Dec 17 2004 11:09 pm From: [EMAIL PROTECTED] I'm having trouble writing a regular expression (using Java) to extract out the numeric portion of a String. Some examples are "$.50." --> .50 "$0.50." --> 0.50 "$6.25." --> 6.25 "$12.30." --> 12.30 "$6.25" --> 6.25 "$0.50" --> 0.50 "2350." --> 2350 "10." --> 10 "$23a.4." no match Note that the first character can optionally be a $, and the last character can optionally be a . Thus far I have a regular expression that is ^\\$?(\\d*\\.?\\d*)\\.? which reads "0 or 1 dollar sign, 0 or more digits, 0 or 1 period, 0 or more digits, 0 or 1 period." As far as I can tell this is the correct expression. But I want to extract out what is in-between the parenthesis, as shown in the expression. It's not working and my simple program is below (with results): I would appreciate any help! public static void main(String[] args) { String[] lines = new String[] { "$.50.", "$0.50.", "$6.25.", "$12.30.", "$6.25", "$0.50", "2350.", "10.", "$23a.4."}; String regexp = "^\\$?(\\d*\\.?\\d*)\\.?"; Pattern pattern = Pattern.compile(regexp); for (int i = 0; i < lines.length; i++) { System.out.println("Does text " + lines[i] + " match regexp? " + lines[i].matches(regexp)); if (lines[i].matches(regexp)) { Matcher matcher = pattern.matcher(lines[i]); while (matcher.find()) { System.out.println(" " + lines[i] + " matches " + regexp + " with " + matcher.group() + " Start <" + matcher.start() + ">, End <" + matcher.end() + ">."); } } } } and the output I get is Does text $.50. match regexp? true $.50. matches ^\$?(\d*\.?\d*)\.? with $.50. Start <0>, End <5>. Does text $0.50. match regexp? true $0.50. matches ^\$?(\d*\.?\d*)\.? with $0.50. Start <0>, End <6>. Does text $6.25. match regexp? true $6.25. matches ^\$?(\d*\.?\d*)\.? with $6.25. Start <0>, End <6>. Does text $12.30. match regexp? true $12.30. matches ^\$?(\d*\.?\d*)\.? with $12.30. Start <0>, End <7>. Does text $6.25 match regexp? true $6.25 matches ^\$?(\d*\.?\d*)\.? with $6.25 Start <0>, End <5>. Does text $0.50 match regexp? true $0.50 matches ^\$?(\d*\.?\d*)\.? with $0.50 Start <0>, End <5>. Does text 2350. match regexp? true 2350. matches ^\$?(\d*\.?\d*)\.? with 2350. Start <0>, End <5>. Does text 10. match regexp? true 10. matches ^\$?(\d*\.?\d*)\.? with 10. Start <0>, End <3>. Does text $23a.4. match regexp? false ============================================================================== TOPIC: TOMCAT/MYSQL/JSP http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/6cfdfa12d76632b1 ============================================================================== == 1 of 1 == Date: Sat, Dec 18 2004 7:55 am From: "Kevin Robinson" The error message that I obtain fron the Tomcat command window is as follows: java.sql.SQLException: Communication failure during handshake. Is there a server running on localhost:3306? at org.gjt.mm,mysql.MysqlIO.init(Unknown Source) at org.gjt.mm,mysql.Connection.connectionInit(Unkown Source) at org.gjt.mm,mysql.jdbc2.Connection.connectionInit(Unkown Source) at org.gjt.mm,mysql.Driver.connect(Unkown Source) at java,sql.DriverManager.getConnection(DriverManager.java:512) at java,sql.DriverManager.getConnection(DriverManager.java:193) There is more stuff after this. To me it looks as if it cant find the database on port 3306 but the database is up and running as I can acces it with mysql administrator and SQLyog on prt 3306. The OS is XP home edition and the database server starts up automatically. Thanks "Ryan Stewart" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > <[EMAIL PROTECTED]> wrote in message > news:[EMAIL PROTECTED] > > what error r u getting ?? > > also connection setting should be > > DriverManager.getConnection(connectionURL, "username","password"); > > > > for ex DriverManager.getConnection("jdbc:mysql://localhost:3306/bfg", > > "username","password"); > > > User and password are not required, and he already said he tried them. > > ============================================================================== 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
