George Lin

Greenhorn
+ Follow
since Feb 22, 2006
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by George Lin

Thanks Peter,


Originally posted by Peter Chase:
Eclipse is written in Java, isn't it? Are you sure you didn't attach to Eclipse itself?



I think I should attach to javaw.exe, right?


regards,
George
14 years ago
Thanks Peter,


Originally posted by Peter Chase:
In Visual Studio 2005, use the Tools menu, Attach To Process. Look for the java.exe process.

It's in the Tools menu of VS 2003, as well, as Debug Processes.



I have tried that in Visual Studio 2003, I used Debug --> Process and attach to javaw.exe process.

I have also set some break points in VS 2003, but they never hit when I run Java application from Eclipse 3.2.

Any ideas of what is the issue?


regards,
George
14 years ago
Thanks Peter,


How to attaching Visual Studio to your running Java process?


regards,
George

Originally posted by Peter Chase:
I don't use Visual Studio for developing my native libraries, just occasionally for debugging them.

When you say you set the Command to "java", did you include the full path to the Java executable? If not, I think you should, as there could be more than one Java on your machine.

As for Visual Studio crashing, contact your debugger vendor

How about trying attaching Visual Studio to your running Java process, rather than launching Java from Visual Studio? Does that work?

14 years ago
Thanks Peter,


Originally posted by Peter Chase:
(bartender: I thought JNI was supposed to go in Other APIs. It says Other APIs including JNI)

Anyway...

I don't know of any single tool that can seamlessly debugs Java and native C/C++ code. That doesn't mean that it doesn't exist. In my organisation, we mostly use built-in or free command-line tools - not big on IDEs (unless emacs counts) or buying expensive tools - so there may be some premium product out there that I don't know about.

You certainly can use an ordinary C debugger to debug the C/C++ code that forms your JNI library.

First, make sure it's built with the necessary debug information included (compiler/linker switches).

Then run your Java launcher (e.g. "java[.exe]") in a C/C++ debugger. You can use gdb on Unix or Mac OS X. Or you can use Visual Studio (spit) or WinDBG (yea) on Windows.

You won't get many debugging facilities on the code of the JVM itself, as it has no debug symbols. But once your native library has loaded, you can set breakpoints on your JNI functions, see variable values, examine call stack, catch C++ exceptions etc.

This said, I agree with the previous responder who recommended keeping the C/C++ code as simple as possible and putting the complicated stuff in Java. The C/C++ should be just sufficient to interface with the native facilities you're using. That is assuming you're using JNI for accessing native facilities, rather than for performance; the latter is much less necessary these days, because the latest JVMs are so fast (faster than C, in some cases).

If you need to debug Java and C/C++ in the same session, you can run "jdb[.exe]" (rather than "java[.exe]") in the C/C++ debugger. Works fine ... honest.

Final point: if it's difficult to adjust your Java start-up to run via C/C++ debugger, you can use your ordinary start-up procedure, then attach the C/C++ debugger to the Java process.

[ August 13, 2007: Message edited by: Peter Chase ]



I have tried to set Visual Studio parameters,

in the native DLL Project Properties dialog, I assign Command to java, then set Command argument to,

-classpath "C:\Program Files\Java\jdk1.5.0_06" HelloWorld,

when when debugging from Visual Studio, Visual Studio will crash. Do you know anything wrong with the settings?

I have also tried to run manually from command line,

java -classpath "C:\Program Files\Java\jdk1.5.0_06" HelloWorld

and the result is correct.


regards,
George
14 years ago
Thanks for moving, marc.


Originally posted by marc weber:
I think JNI is a bit advanced for the beginners forum. Let's promote this to the intermediate forum.



Looking forward to reply. :-)


regards,
George
14 years ago
Thanks Remko,

Originally posted by Remko Strating:
I already told you I did a simple test and it worked. I could get a string from an integer,bit,blob field.

Why don't you try it yourself.



I have tried and it works! Cool!


regards,
George
Thanks Stan,


Originally posted by Stan James:
I've done this very thing. I made a Key object that holds an array of values and implements Comparable. You tell it which columns to use for keys, and it assumes that both result sets are in ascending order.

Just looking at it, I used getString() for all columns. I wonder how I didn't get burned by "10".compareTo("2"). Maybe I just got lucky? In the reporting phase I check to see if the column type should be right justified, so I do line up 2 and 10 correctly there.

If you figure out which columns won't work as String and get a good comparable key, the basic algorithm I drag out often is:

Note that a key at end always compares as larger. For my purposes, when the keys match, I optionally do another comparison on all the rest of the columns.

Any of that sound helpful?

[ August 09, 2007: Message edited by: Stan James ]



I am wondering whether getString could work for all types of columns of database, like BLOB, BIT?


regards,
George
Thanks Remko,


Originally posted by Remko Strating:
If you want to compare if the rows are equal. You could just use getString() for every field and then add the values of the different fields to one string and compare this string with an another row-string.

I've tested this with a simple table and query and it worked. For a good working you have to order your table first.

But what database are you using. It could be that your database has a better solution for comparing two tables.



I am wondering whether getString could work for all types of columns of database?


regards,
George
Hello everyone,


I am wondering if I want to debug JNI application (upper layer Java and lower layer C), are there any tools to debug through Java code to C code and return back from C code to Java code.

I am using Eclipse. But I do not find such functions in Eclipse (maybe I miss some plug-ins?). Currently, I can only debug Java code.


thanks in advance,
George
14 years ago
Thanks Remko,


Originally posted by Remko Strating:
I don't know what you exactly mean but have a look at the following url

ResultSet MetaData

With this class you can retrieve metadata of your resultset and this you could use for writing a generic method.



I think in your method, I still need to check the type of columns and write a large switch (for each column type, I need to invoke the type's compare method), right?

Are there any unified way to implement without a large swithc code segment?


regards,
George
Hello everyone,


I am using JDBC to compare the content of two database tables -- writing a general function and two tables are input. The two tables have various types of columns, like VARCHAR, BLOB, INT, FLOAT, etc.

I want to save my time to write various statements to get values by different types and compare them, for example, for VARCHAR, I need to use getString and compare the content by String compare function, and for INT column, I need to use getInt and compare with Integer compare function.

I am wondering whether there are any smart way to implement in an uniformed way so that I do not need to write various switches according to column type.


thanks in advance,
George
Thanks Ulf,


Originally posted by Ulf Dittmer:
If it gets in the way of compiling, you can safely delete it from the source without fear of runtime consequences.



Do you know where to find any samples for @override?


regards,
George
14 years ago
Thanks John,

Originally posted by John Bartlett:
Hi,

if you take a look at @Override it states it has been available since J2SE 5.0 so you'll need the JDK5.0 or higher.

John

[ July 25, 2007: Message edited by: John Bartlett ]



I am looking for samples of how to use @override. Do you have any samples or sample reference?


regards,
George
14 years ago
Hello everyone,


I am using JDK 1.4 and there is a compiling a 3rd party program error because of un-recognized word @override. Could anyone let me know what is the function of @override and in order to use it, which version of JDK is required?


thanks in advance,
George
14 years ago
Hello everyone,


When running my program on Java JVM 5.0, there are strange stack errors. What may be the root cause?

(foo.dll is my JNI invoked native library.)

--------------------
Registers:
EAX=0x0c213e40, EBX=0x00000000, ECX=0x00000000, EDX=0x00000000
ESP=0x0c213e0c, EBP=0x0c213e44, ESI=0x00000000, EDI=0x00000000
EIP=0x0c4e8070, EFLAGS=0x0001024f

Top of Stack: (sp=0x0c213e0c)
0x0c213e0c: 00000000 00000000 00000000 0b97aeb0
0x0c213e1c: 0c4e8232 00000000 00000000 0b97aeb0
0x0c213e2c: 00000000 00000000 00000000 00000000
0x0c213eec: 00000000 00000000 0c213eb4 0c4e8147
0x0c213e4c: 00000000 00000000 0b97ac70 0b97aeb0
0x0c213e5c: 00000000 f5e24244 4e434c53 4854534b
0x0c213efc: 44414552 00000000 00000000 00000000
0x0c213e7c: 00000000 00000000 00000000 00000000

Instructions: (pc=0x0c4e8070)
0x0c4e80f0: 08 8b 4f 08 56 ce 5f 8b 31 33 74 24 08 fa 00 52
0x0c4e8070: 33 ef 33 15 5c 40 45 0c 8e 38 33 89 4f 08 74 04


Stack: [0x0c1e0000,0x0c220000), sp=0x0c21f30c, free space=252k
Native frames: (J=compiled Java code, j=interpreted, Vv=VM cod6, C=native code)
C [foo.dll+0x18070]
C [foo.dll+0x18147]
--------------------


thanks in advance,
George
15 years ago