The information in this article applies to:
This article covers some of the Frequently Asked Questions (FAQ) about the Microsoft SDK for Java. For other Java related FAQs, search the Web at:
http://support.microsoft.com/support for JAVA and FAQ.
Q. 1. When running the JDBC sample, I get java.sql.SQLException: -7ffbfeee (80040112h).
A. Download the two files located under the "ActiveX Data Objects (ADO) version 1.0" section of http://msdn.microsoft.com/downloads/default.asp?MSCOMTB=ICP_DOWNLOADS .
Q. 2. How does the Msdev.exe, in Microsoft® Visual J++® relax the security in Microsoft® Internet Explorer so that my applet can run outside the Java sandbox, despite the fact that it is not in a signed .cab file?
A. In the Microsoft VM that is included with Internet Explorer 3.x, only trusted class files can access resources outside the Java sandbox. Class files from digitally signed .cab files are trusted. If the HTML file is run from Microsoft® Developer Studio® (MSDEV), the class files are also trusted. This can be very helpful during applet development. However, to deliver your applet to other users, you must place them in a signed .cab file.
When executing or debugging a Java applet from MSDEV, the security restrictions in Internet Explorer are relaxed for quick and easy testing. MSDEV prepends the project path to the CLASSPATH environment variable that is used by Internet Explorer. This gives the classes trusted status.
Q. 3. Why does InetAddress.getLocalHost() return localhost/127.0.0.1 in my applet?
A. An untrusted applet isn't allowed to get the real localhost IP address because it opens various types of network attacks. If the Java libs detect an untrusted applet, then they will return the loopback address (127.0.0.1).
JDK 1.02's/1.1's appletviewer will do the same thing unless you've changed the "network access" property in the appletviewer to "unrestricted."
Q. 4. Is it possible for an applet to read a file from my Web server? If so, how?
A. The class below shows how to read a text file named poem.txt from the server.
Note Place the .htm and .class files in the same directory on the Web server along with a text file named poem.txt with at least one line of text:
import java.io.*; import java.net.*; import java.applet.*; import java.awt.*; class ReadFile extends Applet { public void start () { try { URL u2 = new URL(getCodeBase(),"poem.txt"); DataInputStream d = new DataInputStream(u2.openStream()); String s5 = d.readLine(); add(new Label(s5)); } catch (Exception e) { System.out.println("Error: " + e.toString()); } } }
Q. 5. What are common causes of the "Failed to create object" message when trying to instantiate a COM object written in Java?
A. Here are some common causes:
Q. 6. When I have an applet in a <FORM>, it doesn't submit any information to the server. How can I get the applet to submit its information?
A. The applet doesn't submit any information because the information a user would want to submit is specific to the applet. For example, an applet that shows images may want to submit the currently displayed image number, while an applet that displays a clock may want to submit the GMT time. It is up to the programmer to write the methods to submit the applet. The five steps below show one way you might implement submitting an applet:
public int getCurrentImage() { return m_nCurrImage; }
Here is the finished product:
<form action="/scripts/info.dll" method=GET name="myForm" > <applet code=AppletInForm.class id=myapplet width=320 height=240 > </applet> <input type=hidden name="appletImage"> <script language=JScript> function processApplet() { parent.myForm.appletImage.value=document.myForm.myapplet.getCurrentImage(); alert("Sending form: image="+parent.myForm.appletImage.value+" user="+parent.myForm.Username.value); } </script> <br> Username:<input type=text name="Username"><br> <input type=submit value="Please send me the above picture." language="JScript" onClick="processApplet();"> </form>
Q. 7. How can I get showDocument to display a URL, when the URL protocol isn't supported by Java (for example FTP)?
A. The URL class verifies Java protocol support by calling the protocol's Handler class. The four steps below show how to add a protocol and demonstrates how to make the call to showDocument:
.\sun\net\www\protocol\ftp
.\sun\net\www\protocol\ftp\Handler.java. package sun.net.www.protocol.FTP; import java.net.URL; import java.net.URLConnection; import java.net.URLStreamHandler; public class Handler extends URLStreamHandler { public synchronized URLConnection openConnection(URL u) { return new FTPURLConnection(u); } }
package sun.net.www.protocol.FTP; import java.io.IOException; public class FTPURLConnection extends sun.net.www.URLConnection { FTPURLConnection(java.net.URL u) { super(u); } public void connect() throws IOException { throw new IOException("FTP doesn't support connect()."); } }
import java.net.*; public class FTPTest extends java.applet.Applet { public void init() { add(new java.awt.Button("Click to open FTP session.")); } public boolean action(java.awt.Event evt, Object what) { try {URL u=new URL("ftp://ftp.microsoft.com"); getAppletContext().showDocument(u,"FTPFrame"); } catch (Exception e) { showStatus(e.toString()); e.printStackTrace(); } return true; } }
Q. 8. What steps must be followed to use a Java class from a Microsoft® Active Server Page (ASP)?
A. First, you must install build 1257 or later of the Microsoft VM or else install the Microsoft SDK for Java 1.5. Then, follow these steps:
class Simple { int SimpleFn ( int x ) { return x * 2; } }
jvc simple.java
copy simple.class \winnt\java\trustlib
javareg /register /class:simple /progid:Simple
/class: argument is the name of the .class file in your trustlib directory.
/progid: is the name that you will use to create your COM object.
Now your Java class is registered as a COM object and ready to use from ASP.
<html> <body> <h1>Simple Test</h1> The result from SIMPLE is: <% Set SimpleObj = Server.CreateObject("Simple") %> <% = SimpleObj.SimpleFn(5) %> <hr> </body> </html>
That's it! Open your Web browser and point it at YOUR_MACHINE/simple.asp.
Q. 9. How do I redirect output from jview or wjview?
A. Unfortunately, there is not an option or registry setting for jview or wjview that enables Java logging. However, you can redirect the output when invoking an application like the following example:
jview main > javalog.txt
This works for both jview and wjview. Or, you could programmatically direct the output to a file or pipe by reassigning System.out. The following code, which works for jview/wjview and Internet Explorer, shows how this can be done:
if ("true".equalsIgnoreCase(System.getProperty("com.ms.applet.enable.logging") )) { try { String logdir = System.getProperty("java.home"); PrintStream ps = new PrintStream(new BufferedOutputStream(new FileOutputStream(new File(logdir, "javalog.txt"))), true); System.out = ps; // comment line if using SDK 2.0x // System.setOut(ps); // uncomment line if using SDK 2.0x System.err = ps; // comment line if using SDK 2.0x // System.setErr(ps); // uncomment line if using SDK 2.0x } catch (Exception e) { } }
The ability to alter the value of System.out and other system streams may be removed or changed in the future.
Q. 10. When I create an ActiveX control in Java and then call its methods, I get a java.lang.UnsatisfiedLinkError exception. Why can't I call the methods?
A. For the Microsoft VM build 1518:
The problem is that applets aren't ActiveX containers and therefore cannot host ActiveX controls. The call to new myActiveXControl(); doesn't make sense because there is no container to host the control. You should use an <OBJECT> tag in your HTML file, and then pass this object reference to your applet. For an example of how this is done, see the OLEControls sample in the Microsoft Visual J++ samples documentation.
For the Microsoft VM build 2057 (SDK 2.0x):
You need to use the AXComponent class, located in the com.ms.activeX package, to host your ActiveX control.
Q. 11. How do I get the SampleSelect JDBC-ODBC sample to work with the Northwind database that comes with Microsoft® Access?
A. An updated jdbcrel.htm has been placed in the sample pack that details the steps necessary to connect to the Northwind database. The sample pack can be obtained at http://www.microsoft.com/java .
Q. 12. When I call show on a modal dialog, the Microsoft VM continues executing the code after the show call, even though I haven't dismissed the dialog yet. Is this a known bug?
A. This is a bug and has been fixed in the Microsoft VM that is provided in the SDK 2.0x (build 2057 of the Microsoft VM).
Q. 13. Why does System.getProperty("user.name") return null?
A. This is a bug and has been fixed in the Microsoft VM that is provided in the SDK 2.0x (build 2057 of the Microsoft VM).
Q. 14. How do I tell from my Java applet or application what version of the Microsoft VM is installed on the system?
A. Use the SystemVersionManager.getVMVersion static method in com.ms.util package to find the version number of the installed Microsoft VM. The BuildIncrement property will indicate the version the Microsoft VM:
String build; build=SystemVersionManager.getVMVersion().getProperty("BuildIncrement"); System.out.println("Using build "+build);
Q. 15. I am getting the error message "Security Exception: Couldn't connect to with origin from file ***" in my javalog.txt file.
A. This could be caused by changes to the AppletSecurity class, some of these restrictions have been loosened in build 1520 of the VM. This problem was occuring with build 1516 of the VM when loading an applet via a file URL.
For more information, please refer to the following article in the Microsoft Knowledge Base :
Q169815 : PRB: Security Exception when Launching an Applet with Images Build 1520 of the VM, that has a fix to the problem, can be obtained by navigating to http://www.microsoft.com/java/vm/dl_vm151.htm .
Q. 16. How can I execute jview.exe without displaying a DOS box?
A. Use wjview.exe instead of jview.exe. Wjview can be found in the Microsoft SDK for Java.
Q. 17. How can I combine all of my Java application's classes into one executable file?
A. Use jexegen.exe to convert your Java classes into a Win32® application. The Win32 application will still require the Microsoft VM to be installed on the local machine.
Q. 18. Has the support for SafeArray been updated in the Microsoft VM?
A. Yes, see the documentation for the Microsoft SDK for Java 2.0x at http://www.microsoft.com/java/sdk/20/default.htm and follow the link from Packages and Classes to the com.ms.com package then to Class Variant or Class SafeArray.
Q. 19. How do I install the developer version of Classes.zip for the SDK 2.0x?
A. Run the ClassD.exe from the %SDKDIR%\bin directory of the SDK 2.0x, then run javasrc.exe (installed by Visual J++ in the %Windir%\java\classes directory) to extract the Java files. If you do not have Visual J++, use a program that can unzip the *.java files from the Classes.zip file.
Note You may have to delete your old Classes.zip first.
Q. 20. How can I see messages that are printed using System.out.println. In Netscape Navigator, I can see these in the Java Console?
A. For the answer to this question, please see the following article in the Microsoft Knowledge Base:
Q177177 HOWTO: Enabling Messages Printed Using System.out.printIn
Q. 21. How can I enable the Java JIT compiler for my application?
A. If you have enabled JIT in Internet Explorer, your applications will also run in JIT compiler mode. To enable JIT in Internet Explorer choose View, Options, Advanced, Enable Java JIT compiler.
In the registry JIT can be enabled by setting the following to 0x00000001:
HKEY_Current_User\Software\Microsoft\Java VM\EnableJIT
For the latest Knowledge Base articles and other support information on Visual J++ and the Microsoft SDK for Java, see the following page on the Microsoft Technical Support site:
http://support.microsoft.com/support/visualj/
http://support.microsoft.com/support/java/