的确有问题的,还是用1.3.1的吧,正好问问deploytool配置sql2000 jdbc的问题,下面是英文资料,望大家帮忙参考!!
Re: J2EE and SQL2000 Database Connection.......Very urgent.....
Author: riodejaneiro
In Reply To: Re: J2EE and SQL2000 Database Connection.......Very urgent..... Mar 3, 2003 7:39 AM
Reply 11 of 11
Sorry for the delayed response, I have been busy with a company project lately, that I was not able to keep track of this forum anymore. The email address I posted was intended for joining forums such as these, newsgroups, and other memberships in web resources. I was not able check on its contents for quite some time as well.
I would like to thank everyone who replied to my posting, and gave their inputs. I was able to solve my problem through collected info out of the java forums.
I noticed that this problem has been a reccurring trail in the java forums, so I would like to summarize the solutions that have come up so far. This covers using the driver using the Driver Manager and configuring it to work with the J2EE RI.
When I first posted a similar trail on http://forum.java.sun.com/thread.jsp?forum=48&thread=346471 , I was using the Beta Version of the MS SQL Server 2000 Driver for JDBC. That was version 2.3.94.0. It still had limited support for JNDI, since the J2EE configuration for creating data sources uses JNDI, there was no way that the Beta Version could have worked. That was when I was encountering the annoying "No suitable driver found error."
Then I learned that Microsoft has released a Service Pack 1 for their JDBC Driver. It is still freely available to all developers who have a licensed SQL Server 2000. The current version is 7.4.262.0. You may download it from : http://msdn.microsoft.com/downloads/sample.asp
I retried all my settings with this new version, using the following SDKs:
To use the driver in a standalone java application , add the paths of the three jar files that come with the <SQLDRIVER_HOME>\lib directory of the driver package in your CLASSPATH environment variable. In my case, I copied the three jar files in the <J2EE_HOME>\lib\system directory, so that all policy requirements should automatically be granted to the jar files. My CLASSPATH variable looks like this:
To get a connection , use the following URL pattern:
Connection con = DriverManager.getConnection("jdbc:microsoft:sqlserver://<hostname>:<port>;databasename=<dbname>;user=<username>;password=<password> ");
I am running my SQL Server2K on my local machine (Windows 2000 Server), and intended to use it with a database named test , a user account named guest, and password guest123, so my connection URL looks like the following: (Default port number for SQL Server is 1433)
Connection con = DriverManager.getConnection("jdbc:microsoft:sqlserver://localhost:1433;databasename=test;user=guest;password=guest123");
Note that if your SQL Server is running on a different machine , you may encounter an error like "Unable to establish socket connection". In this case, you might need to install the driver on the remote host, and make the same CLASSPATH settings. (I heard that if your SQL Server has SP1 or higher, it should be ready for the JDBC Driver already, but I have not verified this).
Now to use the Driver with the J2EE Server, do the following:
1. Go to <J2EE_HOME>\bin directory. Edit userconfig.bat, as follows:
echo "setting J2EE_CLASSPATH..."
set J2EE_CLASSPATH=D:\j2sdkee1.3.1\lib\system\msutil.jar;D:\j2sdkee1.3.1\lib\system\msbase.jar;D:\j2sdkee1.3.1\lib\system\mssqlserver.jar;
set J2EE_CLASSPATH
rem JAVA_HOME refers to the directory where the Java(tm) 2 SDK
rem Standard Edition software is installed.
echo "setting JAVA_HOME..."
set JAVA_HOME=D:\j2sdk1.4.0
set JAVA_HOME
2. In deploytool, go to Tools -> Server Configuration. In the JTree, under Data Sources, choose Standard. On the JDBC Driver Panel, click on Add , and type com.microsoft.jdbc.sqlserver.SQLServerDriver.
On the Data Sources Panel, add a JNDI name for your data source. I made mine jdbc/SQLServerTest , containing the URL jdbc:microsoft:sqlserver://localhost:1433;databasename=test
Note: For the URL, you must stop in the databasename property, because the username and password will be specified later in the deployment setting of your application. This will make it easier for you to change your setting when needed.
3. Before the next step, you must check your source code of your server component for the Coded Name you used for the JNDI resource you referenced. Here's an example:
String dbName = "java:comp/env/jdbc/TestDB";
InitialContext ic = new InitialContext();
DataSource ds = (DataSource) ic.lookup(dbName);
con = ds.getConnection();
4. For the component that you wish to deploy, open the Resource Refs tab. Under Resource Factories Referenced In Code Panel, click add. Type jdbc/TestDB for the Coded Name, javax.sql.DataSource for the type. Specify whether you want to use Container or Application managed authentication, and whether this resource can be sharable among components.
5. In the Deployment Setting panel , type the JNDI name you specified earlier for the Server DataSource , jdbc/SQLServerTest. You may now specify the user name and password that this component will use.
6. This should have been all there is to the configuration and deployment of your application. However, I still encountered the following error:
"[Microsoft][SQLServer 2000 Driver for JDBC]Error opening/loading com.microsoft.util.transliteration.properties"
If you will unjar the msutil.jar of the driver package, you will find a file called transliteration.properties. I'm not sure about the reason but it looks like the J2EE Server does not have enough privilege to read this file. I would have to thank Scottw512 of the Java Forums because his post has been the most useful so far (http://forum.java.sun.com/thread.jsp?thread=316020&forum=136&message=1274179) . Here's what you must do:
7. Go to <J2EE_HOME>\lib\security folder. Edit server.policy and add the following code:
//permission for MS SQL Server 2000 Driver for JDBC
grant {
// DataSource access
permission java.util.PropertyPermission "java.naming.*", "read,write";
// Adjust the server host specification for your environment
permission java.net.SocketPermission "*.microsoft.com:0-65535", "connect";
permission java.io.FilePermission "${com.sun.enterprise.home}${/}lib${/}system${/}msutil.jar", "read";
};
8. Restart the J2EE Server, and you should be ready to test your Data Source Connection.
For the server.policy entry , I share Scott's concern on whether this additional permission should pose some security issue with your applications.
I have verified the first two permissions , and they are indeed safe to add. The SQL Server 2000 Driver for JDBC Documentation actually instructs that you add this permission if you intend to use it under the Java 2 Platform. What I'm not sure about, is the third permission to allow read access to the msutil.jar. What's included in the documentation is permission for specifying access to temp files or folders, not any of the jar files.
Since this is the first solution that works so far, I'm quite satisfied to use this for my purposes. But I'll still be searching the forums every now and then for any similar trails concerning this.
This is a call to all Java Developers: Maybe some Java Security experts out there could advise us on this ? Please keep this trail active. C'' ,)
Again , I thank Scott for his posts , and everyone who helped.
我设置了:
servlet alias
event listener
error mapping
resource refs
...
但是都不反映到web.xml中,怎么回事呢?
还有我无法通过deployment tool 停止我通过ant 发布的程序,得到一些异常:
----------------------------------------------------------------------
stop: hello1
Running...
java.rmi.ServerException: RemoteException occurred in server thread; nested exception is:
java.rmi.RemoteException: hello1 not found; nested exception is:
javax.management.InstanceNotFoundException: hello1 not found
at com.sun.corba.se.internal.iiop.ShutdownUtilDelegate.mapSystemException(ShutdownUtilDelegate.java:61)
at javax.rmi.CORBA.Util.mapSystemException(Util.java:65)
at org.omg.stub.com.sun.enterprise.tools.deployment.backend._JarInstaller_Stub.stop(Unknown Source)
at com.sun.enterprise.deployapi.actions.ModuleStateAction.run(ModuleStateAction.java:61)
at java.lang.Thread.run(Thread.java:534)
Caused by: java.rmi.RemoteException: hello1 not found; nested exception is:
javax.management.InstanceNotFoundException: hello1 not found
at com.sun.enterprise.tools.deployment.backend.JarInstallerImpl.stop(JarInstallerImpl.java:1286)
at org.omg.stub.com.sun.enterprise.tools.deployment.backend._JarInstallerImpl_Tie._invoke(Unknown Source)
at com.sun.corba.se.internal.corba.ServerDelegate.dispatch(ServerDelegate.java:353)
at com.sun.corba.se.internal.iiop.ORB.process(ORB.java:252)
at com.sun.corba.se.internal.iiop.RequestProcessor.process(RequestProcessor.java:81)
at com.sun.corba.se.internal.orbutil.ThreadPool$PooledThread.run(ThreadPool.java:106)
Caused by: javax.management.InstanceNotFoundException: hello1 not found
at com.sun.enterprise.management.util.J2EEManagementObjectManager.getManagedObjectModule(J2EEManagementObjectManager.java:672)
at com.sun.enterprise.management.util.J2EEManagementObjectManager.stopModule(J2EEManagementObjectManager.java:639)
at com.sun.enterprise.tools.deployment.backend.JarInstallerImpl.stop(JarInstallerImpl.java:1276)