Mark E Hansen wrote:You need to do two things. First, you need to place the MySQL Driver Jar file on the application server's class path. You can do this by editing the script you use to launch the application server (usually run.sh or run.bat, depending on the platform) - this is what I usually do - or you can copy the Jar file to the server's lib directory (JBOSS_HOME/server/default/lib) - I think that's the correct place.
You will need to restart the application server for it to pick up this new driver.
Second, you will need to deploy the datasource xml file. This is the mysql-ds-xml file you mentioned in your original post. This file should be copied to your server's deploy directory (JBOSS_HOME/server/default/deploy).
That's all there is to it.
Mark E Hansen wrote:Sorry about that. When I first read your message, I thought you were having problems deploying the MySQL JDBC drivers. I don't know how I got so far off track.
Hopefully, someone else can answer your Initial Naming Context question.
Best Regards,
A. S. Georgie wrote:
everything goes smoothly until i run client application, i'm getting this error:
javax.naming.NoInitialContextException: Cannot instantiate class: org.jnp.interfaces.NamingContextFactory [Root exception is java.lang.ClassNotFoundException: org.jnp.interfaces.NamingContextFactory]
Jaikiran Pai wrote:
A. S. Georgie wrote:
everything goes smoothly until i run client application, i'm getting this error:
javax.naming.NoInitialContextException: Cannot instantiate class: org.jnp.interfaces.NamingContextFactory [Root exception is java.lang.ClassNotFoundException: org.jnp.interfaces.NamingContextFactory]
Your client (which i believe is a standalone application) classpath, will have to point to JBOSS_HOME/client/jbossall-client.jar
Mark E Hansen wrote:
Your mysql connection-url should look like this:
Mark E Hansen wrote:
Now, as far as the client application goes, can you please tell us what it is? Have you written a stand-alone Java application which you want to access the MySQL database, or is this a J2EE application of some sort?
A. S. Georgie wrote:
Mark E Hansen wrote:
Your mysql connection-url should look like this:
Well actually, my ejb-jar.xml, I ha made it like this :
..........................
<reentrant>false</reentrant>
<env-entry>
<env-entry-name>dbUrl</env-entry-name>
<env-entry-type>java.lang.String</env-entry-type>
<env-entry-value>jdbc:mysql://localhost/TITINE</env-entry-value>
</env-entry>
................
now I changed it the way you’re saying:
.............
<env-entry-value>jdbc:mysql://localhost:3306/TITINE</env-entry-value>
................
Mark E Hansen wrote:
Now, as far as the client application goes, can you please tell us what it is? Have you written a stand-alone Java application which you want to access the MySQL database, or is this a J2EE application of some sort?
Oky, course it’ like this: lik all BMP I have a inherent component, considering ‘Product’:
1. Product
2. ProductHome
3. ProductBean
4. ProductPK
on the other hand, the client standalone is like:
import BMPEBean.Product;
import BMPEBean.ProductHome;
import BMPEBean.ProductBean;
import javax.naming.*;
import javax.rmi.PortableRemoteObject;
import java.util.Properties;
import java.util.Enumeration;
public class Client {
public static void main(String[] args) {
Properties properties = new Properties();
properties.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
properties.put(Context.PROVIDER_URL, "localhost:1099");
try {
InitialContext jndiContext = new InitialContext(properties);
Object ref = jndiContext.lookup("BMPProduct");
ProductHome home = (ProductHome) PortableRemoteObject.narrow (ref, ProductHome.class);
home.create(1, "Product1", "Color1", 1.0);
Product product = home.create(2, "Product2", "Color2", 2.0);
product.remove();
Enumeration enum = home.findByName("Product1");
while (enum.hasMoreElements()) {
product = (Product) enum.nextElement();
System.out.println("Id: " + product.getProductId());
System.out.println("P. Name: " + product.getProductName());
System.out.println("Color: " + product.getDescription());
System.out.println("Price: " + product.getPrice());
}
}
catch(Exception e) {
}
}
}
everything go nicely but when I Execute, I mean I compile the client and it goes smoothly, like im’ saying compile is like this:
Output - Compiler
Command completed. No files needed to be created, changed, or deleted
Finished Client.
but see execute thing says:
Client - I/O
javax.naming.NoInitialContextException: Cannot instantiate class: org.jnp.interfaces.NamingContextFactory [Root exception is java.lang.ClassNotFoundException: org.jnp.interfaces.NamingContextFactory]
at last, I really do think least to emphasize my situation and how it is, I mean, copied all filled needed too, I mean:
1. ‘j2ee-1.4.jar’, ‘javax.ejb.jar’, ‘jbossall-client.jar’ say, all the files in “\jboss-3.2.5\client” to C:\j2sdk1.4.2_05\lib
2. ‘mysql-ds.xml’ to “\jboss-3.2.5\server\default\deploy”
3. ‘mm.mysql-2.0.8-bin.jar’ to “\jboss-3.2.5\server\default\lib”
as I depicted, jboss running, and I copied Product.jar in, you see jboss show it safe and sound, also mysql running too, an’ need to utter that my bat for this part is like the following:
cd \
cd C:\mysql\bin\
C:\mysql\bin\winmysqladmin
C:\mysql\bin\mysql
means that with ‘Product.jar’ there mysql is running too, now, what else I can do to have this tango play , much much more appreciation
Mark E Hansen wrote:I'm afraid I may be a little out of my ability to help, so I would just like to make a couple comments and hope that someone else can also help you.
Mark E Hansen wrote:
First, with regard to the database connection information, you should create the database connection deployment descriptor (the mysql-ds.xml) file, which contains the database connection url, etc., and deploy that by copying it to the server's deploy directory (which you have done). From here, you don't need to reference the database URL, as you are trying to do in your ejb-jar.xml file, where you've created an environment entry named dbUrl. However, you don't appear to be using this anywhere, so I don't think this is causing any problems. I just wanted you to know that your applications should be using the database connection deployed to the application server.
Mark E Hansen wrote:
Secondly, you don't want to extract any JBoss jar files and include the individual files in your application package. Instead, you just want to include the JBoss (and possibly other) Jar files on the CLASSPATH - both when building and running. If you're building the application through the use of a Development Environment, see it's documentation for how to configure the build classpath. As for the runtime, it's still not clear to me what you're running, but it looks like a stand alone Java application. If that's the case, you need to include these additional Jar files on the classpath for the runtime using the -classpath command-line option.
Mark E Hansen wrote:
Finally, with all that out of the way, the error your getting is because the runtime can't find the JBoss class org.jnp.interfaces.NamingContextFactory. This class is in JBoss' jnp-client.jar, so you need to add that Jar file to your application's classpath (via the -classpath command-line option).
and after unjaring 'mm.mysql-2.0.14-you-must-unjar-me.jar' m coping the file named mm.mysql-2.0.14-bin.jar in the mm.mysql-2.0.14 folder to the JBOSS_HOME\server\default\lib,
JAVA_HOME\bin\java.exe -classpath "...\jbossall-client.jar;JBOSS_HOME\server\default\deploy\Product.jar;" Client
Mark E Hansen wrote:Do you want to have two instances of <local-tx-datasource> in the mysql-ds.xml file? You have one named MySqlDS and one named BMPProduct.
Unless you believe you need both, get rid of one of them. Keep, for example, the one named MySqlDS and any place that needs to reference a datasource should be changed to reference that name.
Mark E Hansen wrote:A stand-alone Java client application is one that contain main(String [] args) {...}
I'm going to take a wild guess and say that it sounds to me like you're trying to write a stand-alone Java client application that will make calls to your EJBs deployed on the JBoss application server. Does that sound right?
Mark E Hansen wrote:A stand-alone Java client application is one that contain main(String [] args) {...}
I'm going to take a wild guess and say that it sounds to me like you're trying to write a stand-alone Java client application that will make calls to your EJBs deployed on the JBoss application server. Does that sound right?
You would create a J2EE application which contains your EJBs, deploy the application to the JBoss application server where they would be ready to accept requests. You could then create a stand-alone Java client application to get a reference to the EJB and make calls to it. Is this what you're trying to do?
yesMark E Hansen wrote:
1. Do you need the client application to talk to the database, or will it just talk to the EJB and let the EJB deal with the database?
Mark E Hansen wrote:
2. Is your J2EE application already deployed and working in some other way? In other words, are the EJBs running and being accessed by some other application, like a Servlet in your J2EE application?
Mark E Hansen wrote:
My own J2EE experience is rather limited, so I'm not sure how much I'm helping. Perhaps someone that sees more about what you're doing will offer some help as well?
Mark E Hansen wrote:Do you want to have two instances of <local-tx-datasource>
in the mysql-ds.xml file? You have one named MySqlDS and one named BMPProduct.
Unless you believe you need both, get rid of one of them.
Keep, for example, the one named MySqlDS and any place that needs to reference a
datasource should be changed to reference that name.
Note that the mysql-ds.xml datasource is for use by the components deployed
to the JBoss application server, and not by your stand-alone Java client application.
Mark E Hansen wrote:I'm not sure what you're doing here.
It sounds like you're finding the JDBC connector Jar file and copying it to the
application server's lib directory so it will be on the server's classpath.
If so, this is fine. However, I'm using MySQL ConnectorJ,
version 5.1.10 and it's Jar file is named mysql-connector-java-5.1.10-bin.jar -
I'm not sure what you're using.
Mark E Hansen wrote:I have to wonder if the No suitable driver found error
is the result of having two local-tx-datasource entries in your mysql-ds.xml file?
Mark E Hansen wrote:Now here I'm once again confused.
You're running a stand-alone Java client application by pointing to a
Jar which you have deployed to the JBoss application server.
If you have a stand-alone client application, don't place its files in
the JBoss deploy directory. If you have a deployed entity
(like a J2EE web application), don't try to run it like it was a stand-alone Java client application.
Are you perhaps confusing the two?
Mark E Hansen wrote:I don't think you want to copy Product.jar to the deploy directory.
Can you please explain why you think you should? Perhaps it will help me see what I am missing.
So, the stand-alone Java client application will not use the datasource
you've deployed to the JBoss application server. That datasource will be used by the
J2EE components deployed to the server, like the EJBs, etc.
The stand-alone application will create it's own connection with something like this:
Jaikiran Pai wrote:Hmm, too much contents in the posts
Questions to the original poster -
1) Why are you trying BMP which is deprecated in the recent years?
2) Why JBoss-3.2.5, which again is too old.
Mark E Hansen wrote:
Wow, there's a lot of stuff in there to read. I'll do my best, but no promises that I won't miss something
Mark E Hansen wrote:
I noticed that your <datasource> doesn't have a user name or password. Also, you still have question mark charactrers after the <driver-class> element?
Mark E Hansen wrote:
As far as the version of the MySQL JDBC driver, you can choose which ever one you like. I think I downloaded the most current version, and was surprised to see you using something that sounded completely different. Did you get your JDBC driver from the MySQL web site? Anyway, that was the only reason I questioned it. You can you whatever driver works for you. I found the connector-J driver here: http://www.mysql.com/products/connector/
Mark E Hansen wrote:
Whichever JDBC driver you decide to use for MySQL, make sure you remove the other driver files, so you don't end up with dual driver files/Jars in the application server's lib directory.
Mark E Hansen wrote:
In looking at your ejb-jar.xml, I'm confused at why you're including environment entries for dbUrl, dbUserName and dbPassword. Anything deployed to the application server should use the datasource (deployed as mysql-ds.xml) to connect to the database. What is using these environment entries?
Mark E Hansen wrote:
Now, on to the mile-long server.log file ...
It starts with a message that a file cannot be found. Do you know what this is? Is it important?
Mark E Hansen wrote:
So it seems the application server is still having a hard time finding the driver class for your datasource, or the URL is not in the correct format for your driver class. I still don't know which driver class you're using, as you've mentioned a couple different versions of which I'm not familiar.
One think you can do to make sure you're URL is correct for your driver class is to write a simple stand-alone Java application (like I showed above) which just connects to the database.
Mark E Hansen wrote:
# 06:09:37,734 ERROR [LogInterceptor] EJBException, causedBy: java.lang.NullPointerException
# at BMPEBean.ProductBean.ejbCreate(ProductBean.java:60)
# at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
It seems there is a problem at line 60 of your ProductBean.java. You'll have to look at that and see why it would get a NullPointerException. Probably you're using a variable which is not set.
Mark E Hansen wrote:
Can you please show your ejbCreate method of your Bean? My guess is you're using the environment entries to create a database connection.
Mark E Hansen wrote:
My hope is that someone that knows more about what you're trying to do in your ejbCreate will chime in here, as we're getting beyond my current ability to help.
Mark E Hansen wrote:
I see now that you are using Bean Managed Persistence. I've never used this, so my help may be even more limited.
Mark E Hansen wrote:
If you can show the source code of your Bean (this is what I meant by show us your ejbCreate method, by the way - I meant show the source code for your ejbCreate() method ), we can see how you are creating the connection. My guess is that you are trying to create it as if you were a stand-alone Java application, when you should be getting it from the datasource (and not using those environment entries).
Mark E Hansen wrote:
Note that as I've not used Bean Managed Persistence, I'm not clear on how you are supposed to get a connection to the database in this case. Perhaps someone else can clarify this?
Mark E Hansen wrote:
If you're just trying to lean about EJB, can I make a suggestion? I'm doing the same and am using the book EJB3 in Action from Manning Publications. This has been an excellent book (so far) and I've learned a lot.
Also, I'm using Eclipse and JBoss Tools for Eclipse, which make creating J2EE applications easier. If you're willing to use Eclipse instead, I can provide links to the tools, and a link to a very good tutorial which walks you through creating the first J2EE application on JBoss.
Best Regards,
A. S. Georgie wrote:
Dear Mark that would be definitely big honor to me have your regarding links, books...
Best regards...
Mark E Hansen wrote:
Mark E Hansen wrote:
In any case, if your Bean code is making use of the environment entries, then the entries should be included in the ejb-jar.xml file. As I said above, I wonder if this is the correct way for your Bean to get a connection to the database.
As far as the datasource descriptor goes, it will need the user name and password (if required by the underlying database), so you should add those. My application's mysql-ds.xml file looks like this:
Mark E Hansen wrote:
This is for MySQL Connector-J JDBC Driver version 5.1.10. Your JDBC driver may require a different format. The documentation for your driver should describe this. Note that if you're not using the datasource in your case (because you're creating a connection to the database using the environment entries, etc.), then the datasource descriptor doesn't matter, as it's not being used.
Mark E Hansen wrote:
...
Mark E Hansen wrote:I'm glad you found the source of the "cannot find the file" message.
However, if you just place the Jar in the correct location (in the application server's lib directory) or add it to the classpath used by the application server (by updating the script used to start the server - usually run.bat), then you don't need to copy the file each time you start the server.
Mark E Hansen wrote:
To find the database, you don't need the environment entries for dbUrl, dbUserName and dbPassword. Instead, just deploy the mysql-ds.xml datasource, and look up the connection from the JNDI namespace.
Mark E Hansen wrote:
As for the datasource url, you don't need to provide the user name and password as parameters in the url if you include the user-name and password XML elements. I don't know what will happen if you use both as I've never done that.
Mark E Hansen wrote:
I think you should not use the environment.lookup(...) to get the environment entries and create the database connection using DriverManager. Instead, I think you should just lookup the datasource deployed on the application server (deployed in mysql-ds.xml) and use that directly. Then you don't need to include the environment entries in the ejb-jar.xml.
On to the error you're getting: No suitable driver found for jdbc:mysql://localhost:3306/TITINE?user=Solar;password=Sun
It seems one of two things are happening:
1. The application server cannot find the Driver class, possibly because the correct Jar file is not on the application server's classpath.
2. The URL is not appropriate for the Driver class. You would have to look at the documentation for your specific driver class and verify that the URL you're providing is correct.
My guess is that the problem is that the correct Jar is not on the server's classpath.
A. S. Georgie wrote:
actually, i just wanned to do the same but Jboss just looks the around ejb-jar.xml and about mysql-ds.xml it just adds these lines:
07:09:33,968 INFO [dbUrl] Bound connection factory for resource adapter for Con
nectionManager 'jboss.jca:service=LocalTxCM,name=dbUrl to JNDI name 'java:/dbUrl
'
but for dbUrl, ... looks in ejb-jar.xml ???
A. S. Georgie wrote:
then i just try infinite drivers to find out this ...
Mark E Hansen wrote:
The above output is JBoss deploying the datasource (mysql-ds.xml). It has nothing to do with the environment entries you've added to the ejb-jar.xml file. In fact, your Bean code is the only thing (that we've seen so far) which is using those environment entries. Like I said before, you can just remove those environment entries, and in your Bean code just do a look-up of the Datasource, rather than using the environment entries to create a DriverManager.
Mark E Hansen wrote:
I'm not sure what you mean here.
Mark E Hansen wrote:
If your database is MySQL, then I'm not sure why you wouldn't use their most current driver. If someone else recommended a different drive, throw that away and get the driver provided by the MySQL folks. It's their database. If you feel you need to use a different driver, can you please explain why?
In a previous post, I posted a link to the MySQL site where you can download the Connect-J driver, version 5.1.10. Get that and follow it's instructions for installation and configuration - I can help with that if you need it. It's pretty simple. Once that is done correctly, it should resolve the "No suitable driver" error you're getting - which I think is your only remaining problem.
Mark E Hansen wrote:Well, if you want to use SQL Server, the driver I've had the most luck with is the jTDS driver, which you can find here: http://jtds.sourceforge.net/
Good luck with your project.
"To do good, you actually have to do something." -- Yvon Chouinard
Smokeless wood heat with a rocket mass heater
https://woodheat.net
|