comp.lang.java.programmer http://groups-beta.google.com/group/comp.lang.java.programmer [EMAIL PROTECTED]
Today's topics: * SQL object to int - 4 messages, 3 authors http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/87e630d1130e02a3 * how to get KeyPressed event inside JWindow - 3 messages, 2 authors http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/26a3c33df985c317 * 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" - 1 messages, 1 author http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/4f04fef73a25ccc0 * timout on line of code - 1 messages, 1 author http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/85ddb5609baca4a0 * JSP web hosting companies? - 2 messages, 2 authors http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/6b174e4eeec12692 * Web Hosting With JSP/Servlet/MySQL - 1 messages, 1 author http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/395845611c67463c * bit manuplation with java - 1 messages, 1 author http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/4c3bf92e3489752 * equals vs == - 1 messages, 1 author http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/93c9522d56ea8805 ============================================================================== TOPIC: SQL object to int http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/87e630d1130e02a3 ============================================================================== == 1 of 4 == Date: Sun, Dec 19 2004 2:33 am From: "Ann" "Lee Fesperman" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > Ann wrote: > > > > I have a MySQL database; two of the columns are int(5). > > I wrote a method to extract a tuple and put it into an > > Object[][] myData; using getObject() > > How can I get the integer values? > > Using trial and error, the following works, but it looks awful. > > > > int x = Integer.parseInt(myData[0][3].toString()); > > int(5) is not standard, but if the JDBC driver follows the spec, getObject() should > return an Integer object for those columns. In that case, you can do: > > int x = ((Integer) myData[0][3]).intValue(); > > ... which looks a little better ;^) > > Be sure and check your driver though; I think some MySQL JDBC drivers don't provide that > (proper) functionality. > > -- > Lee Fesperman, FFE Software, Inc. (http://www.firstsql.com) > ============================================================== > * The Ultimate DBMS is here! > * FirstSQL/J Object/Relational DBMS (http://www.firstsql.com) This is what I was looking for, thanks. I use MySQL and specified x int(5) using the mysql console. The 5 means that mysql will print output will be 5 characters or less. With JDBC, a java Object that contains a java Integer is returned, and the (5) is totally ignored as it should be. == 2 of 4 == Date: Sun, Dec 19 2004 3:19 am From: "Tony Morris" "Lee Fesperman" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > Ann wrote: > > > > I have a MySQL database; two of the columns are int(5). > > I wrote a method to extract a tuple and put it into an > > Object[][] myData; using getObject() > > How can I get the integer values? > > Using trial and error, the following works, but it looks awful. > > > > int x = Integer.parseInt(myData[0][3].toString()); > > int(5) is not standard, but if the JDBC driver follows the spec, getObject() should > return an Integer object for those columns. This is blatantly incorrect. JDBC 3.0 Specification TABLE B-6. > In that case, you can do: > > int x = ((Integer) myData[0][3]).intValue(); > > ... which looks a little better ;^) Since the suggestion is on a false premise, it is wrong (the downcast may not succeed), but suppose it wasn't, the suggestion is nasty anyway. Avoid downcasts at all costs - abstraction aids future maintenance. It might "look a little better" to you (I prefer blondes to brunettes), but it's terrible form. -- Tony Morris http://xdweb.net/~dibblego/ == 3 of 4 == Date: Sun, Dec 19 2004 4:11 am From: "Ann" "Tony Morris" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > "Lee Fesperman" <[EMAIL PROTECTED]> wrote in message > news:[EMAIL PROTECTED] > > Ann wrote: > > > > > > I have a MySQL database; two of the columns are int(5). > > > I wrote a method to extract a tuple and put it into an > > > Object[][] myData; using getObject() > > > How can I get the integer values? > > > Using trial and error, the following works, but it looks awful. > > > > > > int x = Integer.parseInt(myData[0][3].toString()); > > > > int(5) is not standard, but if the JDBC driver follows the spec, > getObject() should > > return an Integer object for those columns. > > This is blatantly incorrect. > JDBC 3.0 Specification TABLE B-6. > > > In that case, you can do: > > > > int x = ((Integer) myData[0][3]).intValue(); > > > > ... which looks a little better ;^) > > Since the suggestion is on a false premise, it is wrong (the downcast may > not succeed), but suppose it wasn't, the suggestion is nasty anyway. > Avoid downcasts at all costs - abstraction aids future maintenance. It might > "look a little better" to you (I prefer blondes to brunettes), but it's > terrible form. > > -- > Tony Morris > http://xdweb.net/~dibblego/ Now I am confused. Maybe I am the beneficiary of dumb luck. Here is more detail. My database table is like this: mysql> describe tbl000; +-------+---------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +-------+---------------+------+-----+---------+----------------+ | i | int(5) | | PRI | NULL | auto_increment | | f | double(14,3) | YES | | NULL | | | t | timestamp(14) | YES | | NULL | | | x | int(5) | | | 0 | | | y | int(5) | | | 0 | | +-------+---------------+------+-----+---------+----------------+ 5 rows in set (0.03 sec) mysql> select * from tbl000; +---+---------+----------------+-----+-----+ | i | f | t | x | y | +---+---------+----------------+-----+-----+ | 1 | 104.000 | 20041218211840 | 98 | 65 | | 5 | 104.000 | 20041218211844 | 301 | 105 | | 6 | 104.000 | 20041218211844 | 415 | 263 | +---+---------+----------------+-----+-----+ 3 rows in set (0.00 sec) In java I do this: "SELECT * FROM tbl000" using a "execute" statement and get a result set. Then I put the data in the result set into an array of Objects; Object[][] data; int k = 0; while (rec.next()) { for (int i = 0; i < numCols; i++) { data[k][i] = rec.getObject(i + 1); } k++; -------------- >From the source file C:\j2sdk1.4.2\src\java\sql\ResultSet.java: /** * <p>Gets the value of the designated column in the current row * of this <code>ResultSet</code> object as * an <code>Object</code> in the Java programming language. * * <p>This method will return the value of the given column as a * Java object. The type of the Java object will be the default * Java object type corresponding to the column's SQL type, * following the mapping for built-in types specified in the JDBC * specification. If the value is an SQL <code>NULL</code>, * the driver returns a Java <code>null</code>. <snip> * @param columnIndex the first column is 1, the second is 2, ... * @return a <code>java.lang.Object</code> holding the column value * @exception SQLException if a database access error occurs */ Object getObject(int columnIndex) throws SQLException -------------- Doesn't this mean in effect that, for the x and y columns, it stuffs an Integer into the Object? If it didn't do it this way, I would expect that intValue() would barf, but int x = ((Integer) myData[0][3]).intValue(); works fine. == 4 of 4 == Date: Sun, Dec 19 2004 12:19 am From: Dave Glasser Lee Fesperman <[EMAIL PROTECTED]> wrote on Sun, 19 Dec 2004 01:47:09 GMT in comp.lang.java.programmer: >Ann wrote: >> >> I have a MySQL database; two of the columns are int(5). >> I wrote a method to extract a tuple and put it into an >> Object[][] myData; using getObject() >> How can I get the integer values? >> Using trial and error, the following works, but it looks awful. >> >> int x = Integer.parseInt(myData[0][3].toString()); > >int(5) is not standard, but if the JDBC driver follows the spec, getObject() >should >return an Integer object for those columns. In that case, you can do: > > int x = ((Integer) myData[0][3]).intValue(); > >... which looks a little better ;^) But this would be safer (the cast, that is) and give the same result: int x = ((Number) myData[0][3]).intValue(); -- Check out QueryForm, a free, open source, Java/Swing-based front end for relational databases. http://qform.sourceforge.net If you're a musician, check out RPitch Relative Pitch Ear Training Software. http://rpitch.sourceforge.net ============================================================================== TOPIC: how to get KeyPressed event inside JWindow http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/26a3c33df985c317 ============================================================================== == 1 of 3 == Date: Sun, Dec 19 2004 2:53 am From: William Zumwalt A JWindow class is my main class (w/o all the title, min, max controls, etc...) and I've implemented a KeyListener to it. I have a MouseListener that works fine. But when I add a KeyListener, nothing happens when I press the keys ... keyPressed(KeyEvent ke) catches nothing. Inside the JWindow I have a JPanel which I set the focus to true (cause I think you have to have focus on a component to get the key). panel.setFocusable(true), but I still don't see any KeyPressed events happening. Anyone have any ideas what's going on here. Any help much appreciated. Will == 2 of 3 == Date: Sat, Dec 18 2004 7:24 pm From: [EMAIL PROTECTED] I think you also need to call the method requestFocus() == 3 of 3 == Date: Sun, Dec 19 2004 5:38 am From: William Zumwalt I did this, actually, I did requestFocusInWindow() since it was suggested in the api docs over requestFocus(), and it still didn't work. requestFocusInWindow() returned false. My component is displayable and focusable so I'm not sure what is wrong here. In article <[EMAIL PROTECTED]>, [EMAIL PROTECTED] wrote: > I think you also need to call the method requestFocus() > ============================================================================== 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 8:10 pm From: Chris Smith Tony Morris <[EMAIL PROTECTED]> wrote: > "two-dimensional array is really nothing but an array whose elements are > arrays." > > This is the part that is not true. > A two-dimensional array is certainly not an array of arrays and vice versa. > They are not synonymous; the only real relationship is that one may > conceptualise each in a similiar fashion. The actual quote above is "Remember that a so-called 'two-dimensional array' is really nothing but an array whose elements are arrays." I'm not sure why you misquoted it above, but if you missed the first part of the sentence, that explains the confusion. In other words, I said that what Jeff was calling a two-dimensional array is, in reality, an array whose elements are arrays. How did I know what Jeff meant by saying two-dimensional arrays? Because we're in a Java newsgroup, and there are no true two-dimensional arrays in Java. Unless the conversation spans several languages, the phrase "two- dimensional array" is perfectly clear. -- www.designacourse.com The Easiest Way To Train Anyone... Anywhere. Chris Smith - Lead Software Developer/Technical Trainer MindIQ Corporation ============================================================================== TOPIC: How to change 3 to "003" http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/4f04fef73a25ccc0 ============================================================================== == 1 of 1 == Date: Sat, Dec 18 2004 8:21 pm From: Chris Smith Tony Morris <[EMAIL PROTECTED]> wrote: > > What's printf? I only know print and println. > > It's a method. Note that it's also rather new. You'll need the 1.5.0 (aka 5.0) version of the Java platform to use it. That's what you probably ought to be using for new development anyway, but it will take several existing systems a while to catch up, so you'll have to wait on those. Also note that (perhaps to make a point) Tony's code worked as you want for your specific test input of 3, but probably wouldn't do what you want for inputs outside the range of [0..9]. The point Tony might have been trying to make is that you never really specified what you want to see happen in many cases. That also lies behind the choice between DecimalFormat or NumberFormat in other forks of this same thread. -- www.designacourse.com The Easiest Way To Train Anyone... Anywhere. Chris Smith - Lead Software Developer/Technical Trainer MindIQ Corporation ============================================================================== TOPIC: timout on line of code http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/85ddb5609baca4a0 ============================================================================== == 1 of 1 == Date: Sat, Dec 18 2004 8:57 pm From: Knute Johnson Ike wrote: >>Just what would make that line of code hang? >> >>-- >> >>Knute Johnson >>email s/nospam/knute/ > > > A google search reveals numerous times others have, in the past, had > inexplicable, eternal hanging on: > > URLConnection.getInputStream(); > > > > Under all different JVMs. Has anyone ever figured out the resolution to > this? We havent changed anything, just, suddenly, faced with eternal hanging > on this particular line. -Ike > > > 1.5 has a setReadTimeout() that will throw a SocketTimeoutException if the read timeout is exceeded. If you can't use 1.5, you could use an alligator but it would have to close your program. There was a similar problem with a feature of JavaSound before 1.5 came out and it could hang. Use a Timer to call System.exit() if it waits too long. -- Knute Johnson email s/nospam/knute/ ============================================================================== TOPIC: JSP web hosting companies? http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/6b174e4eeec12692 ============================================================================== == 1 of 2 == Date: Sat, Dec 18 2004 9:26 pm From: [EMAIL PROTECTED] I have account at http://www.eatj.com/index.jsp. It is good one. Daniel wrote: > Does anyone know of web hosting companies supporting JSP? == 2 of 2 == Date: Sun, Dec 19 2004 6:18 am From: "Roy Epperson" www.kattare.com <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] >I have account at http://www.eatj.com/index.jsp. It is good one. > Daniel wrote: >> Does anyone know of web hosting companies supporting JSP? > ============================================================================== TOPIC: Web Hosting With JSP/Servlet/MySQL http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/395845611c67463c ============================================================================== == 1 of 1 == Date: Sat, Dec 18 2004 9:36 pm From: [EMAIL PROTECTED] This one is good. http://www.eatj.com/index.jsp ============================================================================== TOPIC: bit manuplation with java http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/4c3bf92e3489752 ============================================================================== == 1 of 1 == Date: Sat, Dec 18 2004 11:21 pm From: [EMAIL PROTECTED] well hi ther i have a strange question about bitmanuplation if i have a set of bits such as 10110011 which can be any thing arrays of 1 and 0 or may be string or mostly BitSet is there is away to convert it to byte or may be to any other premitive type such as int or char with the rest of the bits be zeros ??!! for example if i have this stream of bits 00101 can i convert it to integer with this bit representation 00000000 00000000 00000000 00000101 which equals to 5 hope i will find an answer to my question and thanks very much in advance ============================================================================== TOPIC: equals vs == http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/93c9522d56ea8805 ============================================================================== == 1 of 1 == Date: Sun, Dec 19 2004 1:12 pm From: "Manish Hatwalne" You may want to read this - http://www.geocities.com/technofundo/tech/java/equalhash.html - Manish "<- Chameleon ->" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > if (s instanceof String) { > if (s == "a string"); > if (s.equals("a string")); > } > > what is the difference between s.equals and s == ??? > > When I use s == "something", many times if s == "something", returns false! > > Instead s.equals works correct always. > > Is there something that I dont know? ============================================================================== 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
