comp.lang.java.programmer http://groups-beta.google.com/group/comp.lang.java.programmer [EMAIL PROTECTED]
Today's topics: * What's wrong with BasicArrowButton? - 1 messages, 1 author http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/e6d7b9492ffcaa1a * How secure is Java? - 3 messages, 3 authors http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/38d2eda5f6def0e3 * JTree Directory System - 4 messages, 2 authors http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/65ea2f59800e25b6 * loading a class whose bytecode comes in a byte[] - 1 messages, 1 author http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/4e991c30dd027000 * efficient network transfer - 5 messages, 4 authors http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/6996ec6c1fb6cf53 * Java Thread Analysis - 1 messages, 1 author http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/c30c46b2c50ca5f * 'A'++ == 'B': Always True? - 2 messages, 2 authors http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/bb79b41e32f311b2 * Access Oracle Objects via PLSQL from JDBC - 1 messages, 1 author http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/f049290e884fb671 * How to write an efficient maximum function? - 1 messages, 1 author http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/f759ff7cc130859e * Deserializing in JDK1.5 without unchecked cast warning - 1 messages, 1 author http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/f79675ff00f1ea8d * Time conversion problem. - 3 messages, 3 authors http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/1726e3482ae3b094 * Return jbyte to a C function (JNI) - 1 messages, 1 author http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/dff0a986d461c81 ========================================================================== TOPIC: What's wrong with BasicArrowButton? http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/e6d7b9492ffcaa1a ========================================================================== == 1 of 1 == Date: Wed, Nov 17 2004 12:20 pm From: Andrew Thompson <[EMAIL PROTECTED]> On Wed, 17 Nov 2004 20:01:36 GMT, DeMarcus wrote: > Why doesn't javax.swing.plaf.basic.BasicArrowButton <http://www.physci.org/codes/javafaq.jsp#cljg> is -> > get the same Look-and-Feel as the rest of the components? It may have something to do with your code. <http://www.physci.org/codes/sscce.jsp> -- 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: How secure is Java? http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/38d2eda5f6def0e3 ========================================================================== == 1 of 3 == Date: Wed, Nov 17 2004 12:29 pm From: Andrew Thompson <[EMAIL PROTECTED]> On Wed, 17 Nov 2004 19:54:01 +0000, Steve Horsley wrote: > hiwa wrote: >> Do you happen know, what would happen if we, with root privilege, .. > An applet run within a browser would (normally) not be allowed to even > read files on the disk, certainly not launch other proccesses with root > privilege. Yes, but since applets have now been mentioned a second time, I will point out that a signed applet (for which the user accepts the signed code) can have every bit as much destructive power as an application ..unless it crashes the browser in the course of it's shenanigans. ;-) -- 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 == 2 of 3 == Date: Wed, Nov 17 2004 1:46 pm From: "Ann" <[EMAIL PROTECTED]> "hiwa" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > Do you happen know, what would happen if we, with root privilege, run > an rm -fr / or equivalent by using Runtime#exec() or java.io.File > methods? Why is this not obvious. Either Java is able to understand the ramifications of every string it sees, or it doesn't. == 3 of 3 == Date: Wed, Nov 17 2004 1:51 pm From: steve <[EMAIL PROTECTED]> On Wed, 17 Nov 2004 18:29:09 +0800, hiwa wrote (in article <[EMAIL PROTECTED]>): > Do you happen know, what would happen if we, with root privilege, run > an rm -fr / or equivalent by using Runtime#exec() or java.io.File > methods? looks like the students are upto page 2 in their "how to learn java" course work. ========================================================================== TOPIC: JTree Directory System http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/65ea2f59800e25b6 ========================================================================== == 1 of 4 == Date: Wed, Nov 17 2004 12:39 pm From: [EMAIL PROTECTED] (seung_shin) I am new to using JTree in JAVA. I implemented my own FileSystemModel that implements TreeModel. It displays directories only in the file system. It works fine except I get C:\Mailbox C:\Mailbox\Inbox C:\Mailbox\Sentbox C:\Mailbox\Savedbox C:\Mailbox\Savedbox\Notes How and where do I change it so it will display Mailbox Inbox Sentbox Savedbox Notes Also it displays the tree collapsed when I run it. I can expand the tree by click on the node but I would like to have an expanded tree as a default. Thanks for help in advance~ Seung == 2 of 4 == Date: Wed, Nov 17 2004 12:45 pm From: Andrew Thompson <[EMAIL PROTECTED]> On 17 Nov 2004 12:39:29 -0800, seung_shin wrote: > I am new to using JTree Better group for GUI questions.. <http://www.physci.org/codes/javafaq.jsp#cljg> >...in JAVA. That's 'Java', it is not an acronym. > ..How and where do I change it so it will display .. Generally in the Java source code. The code you did not post. <http://www.physci.org/codes/sscce.jsp> -- 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 == 3 of 4 == Date: Wed, Nov 17 2004 12:48 pm From: Andrew Thompson <[EMAIL PROTECTED]> On Wed, 17 Nov 2004 20:45:50 GMT, Andrew Thompson wrote: > Better group for GUI questions.. > <http://www.physci.org/codes/javafaq.jsp#cljg> The OP has posted to c.l.j.g. == 4 of 4 == Date: Wed, Nov 17 2004 2:05 pm From: [EMAIL PROTECTED] (seung_shin) From: [EMAIL PROTECTED] (seung_shin) Newsgroups: comp.lang.java.gui Subject: JTree Directory System NNTP-Posting-Host: 157.127.124.141 Message-ID: <[EMAIL PROTECTED]> I am new to using JTree in JAVA. I implemented my own FileSystemModel that implements TreeModel. It displays directories only in the file system. It works fine except I get C:\Mailbox C:\Mailbox\Inbox C:\Mailbox\Sentbox C:\Mailbox\Savedbox C:\Mailbox\Savedbox\Notes How and where do I change it so it will display Mailbox Inbox Sentbox Savedbox Notes Also it displays the tree collapsed when I run it. I can expand the tree by click on the node but I would like to have an expanded tree as a default. Thanks for help in advance~ Seung ========================================================================== TOPIC: loading a class whose bytecode comes in a byte[] http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/4e991c30dd027000 ========================================================================== == 1 of 1 == Date: Wed, Nov 17 2004 1:11 pm From: Luca Rosellini <[EMAIL PROTECTED]> Hi everybody, I have this problem with classloaders: Suppose to have two nodes A and B, node A creates a new class C1 (in the package "Package") which implements an interface (call it myInterface) known to both node A and B. A retrieves the bytecode for C1, stores it in a byte[] and send it in a datagram to node B. In order to properly load the class on B's JVM I actually inherit from ClassLoader and override loadClass method in this way: class myClassLoader extends ClassLoader{ ... ... public Class loadClass(String className, boolean res){ // check if the clas has not yet been loaded // blah blah byte[] classData = buffer_containing_bytecode; Class result = defineClass(className, classData, 0, classData.length); ... ... return result; } } when I need to load the class in my program I do the following (in a try-catch clause): myClassLoader cl = new myClassLoader(); Class myClass = cl.loadClass("P.C1",true); loadClass seems to return successfully, if I use reflection on myClass object to get informations on methods or fields of the class I get correct results. This leads me to think that class is loaded properly. However if I try to create an Instance from myClass using myClass.newInstance() I get an InstantiationException. Any of you knows what I am doing wrong? P.S.: There's another solution that works, but I don't like it, it looks much more like a workaround than a solution and a write on disk is needed: when the bytecode arrives on node B I dump it in a file called "C1.class" in a folder called"Package" using a File a object and calling deleteOnExit() on that File object. when tring to create a new instance from object myClass everything as expected. ========================================================================== TOPIC: efficient network transfer http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/6996ec6c1fb6cf53 ========================================================================== == 1 of 5 == Date: Wed, Nov 17 2004 1:14 pm From: [EMAIL PROTECTED] (uzon) hi, i'm writing a proxy for file transfers. for example, one client sends a file to the proxy which forwards it to another client. i'm writing code for both the clients (send / receive file) and the proxy (forward the file). currently, i have this function to send the file- InputStream fis = new FileInputStream(f.getPath() + f.separator + param.filename); BufferedOutputStream bos = new BufferedOutputStream(os); do { i = fis.read(); if (i != -1) { bos.write(i); } } while (i != -1); the forwarding code is very similar. just the input stream is a socket not a file. the receiving code is also similar. the output stream is to a file not a socket. this is working ok but it's very slow. it takes several minutes for a file that's only a few mb. there are two problems here i don't know how to code better- 1. loading and writing the file byte by byte is REALLY slow. how would i go about doing it with some kind of buffer saving every X amount received and what is the recommended amount? i want to support large file transfers also, so saving the whole file in memory and writing to disk in the end is not good. 2. sending byte by byte on the network (especially for the forwarder- proxy, is also very slow). so here i also need some kind of buffer to accept X amount and then send it. i know there are other sending/receiving functions in java but don't know which to use, or exactly how to use them. any help would be greatly appreciated. thanks in advance, -Aaron == 2 of 5 == Date: Wed, Nov 17 2004 1:29 pm From: Andrew Thompson <[EMAIL PROTECTED]> On 17 Nov 2004 13:14:19 -0800, uzon wrote: > hi, Hi. Please use Upper Case letters at the start of every sentence, Also every time you use the word 'I'. It makes posts easier to read and understand. That is a good thing. > currently, i have this function to send the file- This is not a 'function' (more commonly called a 'method' in Java) so much as a 'code snippet'. It is not very helpful for understanding what you are doing. For example.. > InputStream fis = new FileInputStream(f.getPath() + f.separator + > param.filename); > BufferedOutputStream bos = new BufferedOutputStream(os); > do { > i = fis.read(); What is 'i'? Where is it defined? But no, don't tell me, I have a better idea[1]. Usually when a programmer says 'I am having a problem with this piece of code' thay are wrong. Because it is actually another bit of code somewhere else that is the problem. That is why I suggest you post a short, compilable example of *exactly* what you are doing, from start to end (or better, put it up at geocities or such and post a link) for more tips on examples, check here.. [1] <http://www.physci.org/codes/sscce.jsp> > i know there are other sending/receiving functions in java but don't > know which to use, or exactly how to use them. One step is to go through the Sun IO tutorial <http://java.sun.com/docs/books/tutorial/essential/io/> HTH -- 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 == 3 of 5 == Date: Wed, Nov 17 2004 2:51 pm From: Collin VanDyck <[EMAIL PROTECTED]> > Usually when a programmer says 'I am having a problem with > this piece of code' thay are wrong. Because it is actually Hello! When you are retorting wisely, please take care to double check the spelling on your words! Such obvious misspellings as "thay" detract from the overall readability of your post and smack of carelessness! For future reference, please reference http://www.dictionary.com. == 4 of 5 == Date: Wed, Nov 17 2004 3:00 pm From: Collin VanDyck <[EMAIL PROTECTED]> uzon wrote: > hi, > i'm writing a proxy for file transfers. > for example, one client sends a file to the proxy which forwards it to > another client. > i'm writing code for both the clients (send / receive file) and the > proxy (forward the file). > currently, i have this function to send the file- > > InputStream fis = new FileInputStream(f.getPath() + f.separator + > param.filename); > BufferedOutputStream bos = new BufferedOutputStream(os); > do { > i = fis.read(); > if (i != -1) { > bos.write(i); > } > } while (i != -1); > Have you tried using a BufferedInputStream created on your InputStream? == 5 of 5 == Date: Wed, Nov 17 2004 3:19 pm From: Steve Horsley <[EMAIL PROTECTED]> uzon wrote: > InputStream fis = new FileInputStream(f.getPath() + f.separator + > param.filename); > BufferedOutputStream bos = new BufferedOutputStream(os); > do { > i = fis.read(); > if (i != -1) { > bos.write(i); > } > } while (i != -1); > Firstly, there is a logic error here - you send the final -1 EOF value as the last byte of the file - you shouldn't. fis.read() goes all the way down the I/O stack making an OS call for every byte you read. Better to wrap the FileInputStream in a BufferedInputStream. This will make a big difference. Maybe slightly better still would be to use a byte[] in your read and write calls so that you transfer perhaps 1K at a time. Steve ========================================================================== TOPIC: Java Thread Analysis http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/c30c46b2c50ca5f ========================================================================== == 1 of 1 == Date: Wed, Nov 17 2004 1:38 pm From: [EMAIL PROTECTED] (Carl) Vladimir, thank you for the recommendation. I have downloaded the evaluation version of your profiler and I have taken a few snapshots. I opened all instances of java.lang.Runnable (Thread did not appear to capture the Runnable interfaces.) The profiler is useful in that it seems to answer the questions: How many threads of each class are running? Given a top level thread, what other threads were called by whom? It does not appear to answer: How many ThreadB's did ThreadA invoke? Given a low level thread, what threads invoked it? While the information retrieved is useful I believe that I need to get the other information before I can solve my problem. Any advice is appreciated? [EMAIL PROTECTED] (Vladimir Kondratyev) wrote in message news:<[EMAIL PROTECTED]>... > I think that YourKit Java Profiler (http://www.yourkit.com) can be > useful in your situation. You need to capture memory snapshot and open > all instances of java.lang.Thread. ========================================================================== TOPIC: 'A'++ == 'B': Always True? http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/bb79b41e32f311b2 ========================================================================== == 1 of 2 == Date: Wed, Nov 17 2004 1:41 pm From: steve <[EMAIL PROTECTED]> On Wed, 17 Nov 2004 14:11:40 +0800, Fritz Foetzl wrote (in article <[EMAIL PROTECTED]>): > The program > > public class IncrementCharMain { > public static void main(String[] args) { > char ltr = 'A'; > System.out.println (ltr); > ltr++; > System.out.println(ltr); > } > } > > produces the output > > A > B > > on my system, as I'd expect. However, I'm not very familiar with > Unicode or with Java's handling of character data. Will this program > always produce the same output, regardless of the platform hosting the > JRE/JVM? If not, is there a better way to get "the next letter" > without writing a long and clunky switch statement? > > (I'm cautious because in C, incrementing characters is non-portable; > although adjacent letters have consecutive values in ASCII, this is > not true of EBCDIC. I've never actually seen an EBCDIC system, but > presumably they're out there.) > > ff as long as you "assume" you are using the western alphabet. It would break on all south asian languages ( taiwan/China /Japan), I would guess any language using picto- grams ,would mess it up. An interesting one , would be german, Norwegian, or possibly spanish, but i don't know enough about these languages. personally , I would use an array , or character string, then index into it. that way i would have complete control on what it returns. steve == 2 of 2 == Date: Wed, Nov 17 2004 3:38 pm From: "Doug Pardee" <[EMAIL PROTECTED]> Okay, everyone's been running all over the place with this one, dragging in all sorts of irrelevant stuff like Oriental languages. Let's nail this puppy down. First, I'm going to ignore the title ('A'++ == 'B': Always True?) because as Vincent and Gordon noted, it has two silly typos. Let's talk about the example code instead. First, the character constant 'A' will *always* result in the char value of \u0041. This is defined by chapter 3 of the Java Language Specification (second edition) and by the nature of Unicode. Anyone who thinks that Oriental languages matter doesn't understand the whole point of Unicode: it combines ALL language 'glyphs' into a single unambiguous numbering system. Unicode values \0000-\007F always represent ASCII codes 0-127, okay? So, after the initial assignment ltr='A' we know that the value in ltr is 0x0041. Guaranteed, because 'A' is a character constant. Then after the increment ltr++, we know that the value in ltr is 0x0042, by the rules of 16-bit unsigned arithmetic. This we know corresponds to the value of 'B', because 'B' is also a character constant. But! We cannot say absolutely for sure what will be printed. The System.out.println results in a conversion from the 16-bit Unicode value in the char to 8-bit byte(s). This conversion is performed "using the default character encoding." MOst of the time this is a theoretical issue; you'll usually be using a character encoding that translates 0x0000-0x007F into byte values 0x00-0x7F. A counter-example would be if you were running on an IBM mainframe, and the default character encoding for the JVM is something like ebcdic-us; in that case the output byte values would be EBCDIC (e.g. outputting 0x0041 would result in 0xC1, which is an EBCDIC 'A'). Then there is the question of how those byte values will be interpreted by your display (or print) device. Again, this is primarily a theoretical issue, as most display and print devices map byte values 0x00-0x7F into the appropriate ASCII glyphs. Again, one counter-example is that IBM mainframes terminals and printers will be expecting EBCDIC codes. So: the computation is defined to do what you expect. It will produce the exact same output as System.out.println("A\nB"), whatever that output might actually look like. Now for the question that you didn't ask. If you're working with characters that you read in, rather than 'X' constants that you coded into your program, then you have another character-set conversion to worry about. The basic rules are the same as for the output: in most cases you'll have a direct conversion from the ASCII range 0x00-0x7F into 0x0000-0x007F. But there could be unusual cases such as EBCDIC. In general, these unusual cases will be automagically handled by "the default character encoding" for your JVM and environment. There are two main places that you can run into grief: 1) the default character encoding turns out not to be appropriate, or 2) you try to read/write binary data through the character encoder. In summary: character constants coded into your Java source are absolutely defined. Computations on character values cannot produce variable results. What can vary is the *external* representation on disk, screen, printer, keyboard, TCP/IP packet, or whatever. This is because those media almost universally expect 8-bit coding, and there are any number of possible mappings between those 8-bit values and the internal 16-bit Unicode values. In most simple cases, the default mapping (encoding) will do, but different JVMs running in different environments may have different default encodings. This can cause trouble if, for example, your program finds itself running on an IBM mainframe and uses the default EBCDIC encoding to try to write TCP/IP packet data which has to be in ASCII. You can always specify a particular encoding, but then you need to be careful to specify the right encoding for the situation; e.g., don't force ASCII encoding on an EBCDIC machine if you're outputting to a native EBCDIC device. ========================================================================== TOPIC: Access Oracle Objects via PLSQL from JDBC http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/f049290e884fb671 ========================================================================== == 1 of 1 == Date: Wed, Nov 17 2004 1:48 pm From: steve <[EMAIL PROTECTED]> On Mon, 15 Nov 2004 17:31:35 +0800, Alexey J.1001958768 wrote (in article <[EMAIL PROTECTED]>): > Hello! > > How could I retrieve an OUT parameter of type Oracle Object (create type > ....) from a PL/SQL procedure > via JDBC? > > Is it possible? In oracle demos I couldn't find a such examples.... > > Thank you. > > There are LOADS of examples on the oracle website. however, as you cannot find any!!!. /* * "[Example]Returning a nested table from PLSQL to JAVA" This example uses a JDBC thin client to call a PLSQL stored function which returns an address object list as a nested table. ***NOTE*** This sample only works with Oracle8i. It requires the use of at least the JDBC 815 driver To try it out cut and paste the following into three different files: 1. create.sql - this creates the required sql types 2. getaddr.sql- this creates the plsql function 3. test.java - this calls the plsql and displays the resultset Run 1&2 under the SCOTT/TIGER schema ********** CREATE.SQL ******************************** create or replace type address as object ( street varchar2(60), city varchar2(30), state char(2), zip_code char(5) ); / create or replace type address_list as table of address; / ********** GETADDR.SQL ******************************* -- This stored function requires the creation of two SQL types in the database -- 1. An address type -- 2. An address_list type create or replace function get_address_list return address_list is v_table address_list:=address_list(); i binary_integer; begin -- neccessary to initialize table with a certain size v_table.extend(5); -- fill nested table with values for i in 1..5 loop -- call address object constructor to fill all the fields for each row v_table(i):=address('x','y','z',to_char(i)); end loop; --return the nested table return v_table; end get_address_list; / *********************** test.java *************************************** import java.sql.*; import oracle.sql.*; import oracle.jdbc.driver.*; public class test { Connection conn; OracleCallableStatement cstmt; ARRAY array; ResultSet rs; // JDBC Implementation specific connect string // replace hostname, port, and SID with appropriate values String connectString="jdbc:oracle:thin:scott/[EMAIL PROTECTED]:port:SID"; public static void main(String<> args) { test t=new test(); } public test() { int index; try { // Register JDBC driver and get connection to Oracle8i RDBMS DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver()); conn=DriverManager.getConnection(connectString); // Call the function which returns a nested table cstmt=(OracleCallableStatement)conn.prepareCall("{ ? = call get_address_list() }"); // The return parameter is an ARRAY type (nested table) // The database sql type is ADDRESS_LIST cstmt.registerOutParameter(1,OracleTypes.ARRAY,"ADDRESS_LIST"); cstmt.execute(); // Get the return value and covert it into a JDBC ResultSet array = (ARRAY) ((OracleCallableStatement)cstmt).getOracleObject(1); rs=array.getResultSet(); // Loop through ResultSet rows while(rs.next()) { // Get the object that is in the address_list ( SQL TYPE "ADDRESS" ) // 1st column is the row index // 2nd column is the actual object STRUCT obj= (STRUCT)rs.getObject(2); // Get the column attributes for the object Object<> attrs=obj.getAttributes(); // get each of the object columns // It is the programmers responsibility to know specifically // what these types are. In this case they are all strings. String s1=(String)attrs<0>; String s2=(String)attrs<1>; String s3=(String)attrs<2>; String s4=(String)attrs<3>; System.out.println(s1+","+s2+","+s3+","+s4); } } catch(Exception e) { e.printStackTrace(); } } }*/ /* Calling ScratchBook.transformResult(this, res); //converting a result set to an object public static Object transformResult(Object ref, java.sql.ResultSet res) { try { int col = res.getMetaData().getColumnCount(); String colName = null; for (int i = 1; i <= col; i++) { colName = res.getMetaData().getColumnName(i); try { java.lang.reflect.Field f = ref.getClass().getDeclaredField(colName.toLowerCase()); if (f != null) { if (f.getType() == java.sql.Date.class) { f.set(ref, res.getDate(colName)); } else if (f.getType() == int.class) { f.setInt(ref, res.getInt(colName)); } else { f.set(ref, res.getString(colName)); } } } catch (NoSuchFieldException nfe) { akaan.util.Debug.printDebugMessage("ScratchBoo k.transformResult", "skipping " + colName); } catch (IllegalArgumentException il) { akaan.util.Debug.printDebugMessage("ScratchBoo k.transformResult", "illegal value for " + colName); } } } catch (Throwable t) { akaan.util.Debug.printThrowable("ScratchBook.transformResult", t); } return null; } */ /* *If you add the ROWID pseudocolumn to a query you can retrieve it in JDBC with the ResultSet getString entrypoint. You can also bind a ROWID to a preparedStatement parameter with the setString entrypoint. This allows in-place updates, as in the following example: Statement stmt = conn.createStatement (); // Query the employee names with "FOR UPDATE" to lock the rows. // Select the ROWID to identify the rows to be updated. ResultSet rset = stmt.executeQuery ("select ENAME, ROWID from EMP for update"); // Prepare a statement to update the ENAME column at a given ROWID PreparedStatement pstmt = conn.prepareStatement ("update EMP set ENAME = ? where ROWID = ?"); // Loop through the results of the query while (rset.next ()) { String ename = rset.getString (1); String rowid = rset.getString (2); // Get the ROWID as a String pstmt.setString (1, ename.toLowerCase ()); pstmt.setString (2, rowid); // Pass ROWID to the update statement pstmt.executeUpdate (); // Do the update } //this could be used as follows ("begin open?=getsupplierlist();closesupplierlistcur(); end") //so that you could call an sql routine using a ref cursor & //close it at the sametime, whilst still returning the result set The Oracle JDBC driver supports bind variables of type REFCURSOR. A REFCURSOR is represented by a JDBC ResultSet. Use the getCursor method of the CallableStatement to convert a REFCURSOR value returned by a PL/SQL block into a ResultSet. JDBC lets you call a stored procedure that executes a query and returns a results set. Cast the corresponding CallableStatement to oracle.jdbc.driver.OracleCallableStatement to use the getCursor method. CallableStatement cstmt; ResultSet cursor; // Use a PL/SQL block to open the cursor cstmt = conn.prepareCall ("begin open ? for select ename from emp; end;"); cstmt.registerOutParameter (1, OracleTypes.CURSOR); cstmt.execute (); cursor = ((OracleCallableStatement)cstmt).getCursor (1); // Use the cursor like a normal ResultSet while (cursor.next ()) {System.out.println (cursor.getString (1));} */ ========================================================================== TOPIC: How to write an efficient maximum function? http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/f759ff7cc130859e ========================================================================== == 1 of 1 == Date: Wed, Nov 17 2004 2:17 pm From: Dave Neary <[EMAIL PROTECTED]> Hi, On Tue, 16 Nov 2004 02:00:51 GMT, Ahmed Moustafa said: > What would be the most efficient to write a maximum function in Java? That depends on the data set. You can get the maximum in O(1) on ordered data ;) Otherwise, maximum requires you too look at all data elements, so O(n) is the best you can do. > Initially, I had the comparisons that looked for the maximum inside the > main method and then moved it inside its own method (code is below) to > be called from within the main method (to make the code look prettier), > but that cost me almost 3 additional seconds processing time: How big is the data set? ><code> > private static float maximum (float a, float b, float c, float d) { > float t1 = a > b ? a : b; > float t2 = c > d ? c : d; > return t1 > t2 ? t1 : t2; > } ></code> private static float maximum (float a, float b, float c, float d) { return (a > b ? (a > c ? (a > d ? a : d ) : (c > d ? c : d ) ) : (b > c ? (b > d ? b : d ) : (c > d ? c : d ) ) ); } should gain you a few clock cycles by always doing the same 3 comparisons, but without the temporary variables. Or maybe it won't... > Is there something like C's macros to keep the code clean but to save > the processing time for calling the macro? Java profiles and optimises stuff pretty well when it's inline - I wouldn't be surprised that you're doing yourself out of time simply by moving things to a function. But Java doesn't have an inline function modifier, so... Cheers, Dave. -- David Neary, E-Mail: bolsh at gimp dot org Work e-mail: d dot neary at phenix dot fr CV: http://dneary.free.fr/CV/ ========================================================================== TOPIC: Deserializing in JDK1.5 without unchecked cast warning http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/f79675ff00f1ea8d ========================================================================== == 1 of 1 == Date: Wed, Nov 17 2004 2:59 pm From: "bilbo" <[EMAIL PROTECTED]> As far as I know you currently can't. Sun has defined a @SuppressWarnings annotation that can be used to suppress unchecked warnings, among others, in a section of code. Unfortunately it's not actually implemented in the first Java 1.5 release. So you can add the annotation to your code now and take comfort in the fact that in some future release of the JDK your code will compile with no warnings. See http://www.langer.camelot.de/GenericsFAQ/FAQSections/TechnicalDetails.html#FAQ004 for more information. ========================================================================== TOPIC: Time conversion problem. http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/1726e3482ae3b094 ========================================================================== == 1 of 3 == Date: Wed, Nov 17 2004 3:11 pm From: [EMAIL PROTECTED] (siliconsmiley) I am trying to read a time stamp from an web appliance type device (a Matrics AR400 Reader for those interested). It responds to http queries with XML. Anyway, it's giving me UTC time stamps in hex. This hex number represents the number of SECONDS since Jan. 1 1970, while Java expects this number in milliseconds. I covert the hex string to a long as so: timeUtc = Long.parseLong(timeHex,16) * 1000; The value that I'm getting appears to be off by about 5 hours. It very well may be exactly 5 hours. Anybody know why I might be off by 18,000,000 milliseconds? == 2 of 3 == Date: Wed, Nov 17 2004 3:27 pm From: Eric Sosman <[EMAIL PROTECTED]> siliconsmiley wrote: > I am trying to read a time stamp from an web appliance type device (a > Matrics AR400 Reader for those interested). It responds to http > queries with XML. > > Anyway, it's giving me UTC time stamps in hex. This hex number > represents the number of SECONDS since Jan. 1 1970, while Java expects > this number in milliseconds. I covert the hex string to a long as so: > > timeUtc = Long.parseLong(timeHex,16) * 1000; > > The value that I'm getting appears to be off by about 5 hours. It > very well may be exactly 5 hours. Anybody know why I might be off by > 18,000,000 milliseconds? You're probably either (1) interpreting a UTC time as if it were local time or (2) mistakenly re-adjusting an already-adjusted time. How, exactly, do you determine "the value that I'm getting?" Please show code. -- [EMAIL PROTECTED] == 3 of 3 == Date: Wed, Nov 17 2004 3:30 pm From: Carl <[EMAIL PROTECTED]> siliconsmiley wrote: > I am trying to read a time stamp from an web appliance type device (a > Matrics AR400 Reader for those interested). It responds to http > queries with XML. > > Anyway, it's giving me UTC time stamps in hex. This hex number > represents the number of SECONDS since Jan. 1 1970, while Java expects > this number in milliseconds. I covert the hex string to a long as so: > > timeUtc = Long.parseLong(timeHex,16) * 1000; > > The value that I'm getting appears to be off by about 5 hours. It > very well may be exactly 5 hours. Anybody know why I might be off by > 18,000,000 milliseconds? Does the machine reside in the GMT time zone, or the East coast U.S by any chance? Perhaps you need to adjust for your time zone offset. Carl. ========================================================================== TOPIC: Return jbyte to a C function (JNI) http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/dff0a986d461c81 ========================================================================== == 1 of 1 == Date: Wed, Nov 17 2004 3:42 pm From: [EMAIL PROTECTED] (Ann) I have a program,which reads a String from the user. char buf[128]; const jbyte *jnistr; jsize strsize; jnistr = (*env)->GetStringUTFChars(env,prompt,NULL); if(jnistr==NULL){ return; } strsize = (*env)->GetStringLength(env,prompt); testBuffer(*jnistr,strsize); After converion, it is in the varibale jnistr ,which is a const jbyte. My confusion starts here: How can I pass the const jbyte to a C function, so that the whole string is accessible. When I try to return the jnistr, and accept it as a char parameter in the C function testBuffer(), I can only read the first letter of the string and nothing beyond that. Thank You, Ann ======================================================================= You received this message because you are subscribed to the Google Groups "comp.lang.java.programmer". comp.lang.java.programmer [EMAIL PROTECTED] Change your subscription type & other preferences: * click http://groups-beta.google.com/group/comp.lang.java.programmer/subscribe Report abuse: * send email explaining the problem to [EMAIL PROTECTED] Unsubscribe: * click http://groups-beta.google.com/group/comp.lang.java.programmer/subscribe ======================================================================= Google Groups: http://groups-beta.google.com
