I am a beginner working on a project in Netbeans and using Glasshfish, but I have to deploy on TOMCAT on Elastic BeanStalk. I don't know anything about tomcat. To connect to my database, I use Entity Classes and a named connection jdbc/whatever (I hear this is called a JDNI name) in my persistence.xml.
On the Glassfish server bundled with Netbeans, I added a Connection pool and a JDBC resource. This was done with a GUI. It was super simple. Create the JDBC connection pool after you stuffed the right driver in the right folder by pointing to the location of server/password/etc. Then point the jdbc resource at the pool.
Now I need to do this with TOMCAT and XML. I have no idea what I am doing...
How do I create a connection pool which all my applications can reach?
How do I then get JNDI? set up that persistence.xml can reference and make the magic db stuff happen?
How do I then set up a jdbc authentication realm based on this database?
It was magic in Glassfish is it was so GUI. But I don't have a GUI for TOMCAT.
I am using spring.
Related
My current production setup requires me to share Oracle database connection pools between multiple Spring Boot apps where each app runs via an embedded Tomcat instance.
What options do I have to share the database connection pool among these Spring Boot apps?
Is JNDI an option? If so, could someone explain how storing the connection pool details in say LDAP accessed via JNDI works?
I am trying to deploy my webapp on Tomcat 8 that uses Mybatis 3.2.7 and c3p0 for connection pooling to connect to an SQLServer database. I have the sqljdbc4.jar in my classpath. I query the database during my webapp startup to get some values.
The application works in Tomcat 7, however on Tomcat 8, I cannot connect to the database. I debugged a lot using eclipse and the root cause is in the file BasicResourcePool.class file in c3p0 where it is waiting for resource to become available but then throws an java.lang.InterruptedException.
Due to this, Mybatis is throwing a java.SQL.SQLException and thus my webapp does not start as it cannot connect to the database.
Has someone else upgraded to Tomcat 8 and has successfully used Mybatis-c3p0? If yes am I missing something over here?
Solved this. It was JDBC driver issue. Mybatis isn't very good in showing underlying exceptions it seems.
Found this on tomcat 8's documentation:
Thus, the web applications that have database drivers in their
WEB-INF/lib directory cannot rely on the service provider mechanism
and should register the drivers explicitly.
So, I added a Class.forName() with the appropriate driverClass during app startup and this solved my issue.
I have a Play Framework 2.2.2 application that I am deploying as a .war file and running under Tomcat 7. My application runs for days without problems on my local dev machine (through Play's built in server, not Tomcat), but once I deploy it under Tomcat, after several hours the Tomcat server will lock up, taking down all the other applications running on it as well.
I think the problem is that the BoneCP connection pool in Play, and the built-in connection pool of Tomcat are conflicting. There isn't much or any useful information in the Tomcat logs, so I'm kind of left guessing here.
I'd like to disable the BoneCP connection pooling within my Play application, but cannot find any information on how to do so.
Any advice appreciated!
There are several possible solutions for this, which might be more or less preferrable for your deployment environment.
Play gives you an "out-of-the-box" database connection, which you don't need to use. Drop the Play JDBC component from your build file (remove jdbc from your libraryDependencies) and setup your JDBC connections manually by yourself. For example, you can make a singleton TomcatConnectionPool that has a function getConnection() that gives you the JDBC connection you need for use in your Play actions.
Write your own plugin specifically extending Play's DBPlugin interface so that it's a database plugin. Implement it like Play's BoneCPPlugin but make it use the Tomcat connection pool instead of BoneCP.
Use someone else's already made custom Play Database Plugin, like this one that uses c3p0. I have some anecdotal evidence that c3p0 works well with Tomcat, but your mileage my vary.
I have made an application with the java JDBC driver for MYSQL and that works fine. But now I'm trying to implement a web service into my application and I can't seem to get a connection made. Do I need to use a different driver or different way to connect to the MySQL server?
Thanks
You can use the same driver. Most likely you don't have your connection pool in Glassfish properly set up.
You can read about it here http://docs.sun.com/app/docs/doc/820-7692/ablih?l=en&a=view
You have to put the JDBC driver JAR either in a /lib directory that's visible to Glassfish (if it's shared) or in the WEB-INF/lib of your web service WAR.
You don't say what the error was. If it's a ClassNotFoundException, it means the class loader couldn't find the JDBC driver JAR.
If the error message is "no suitable driver found", it usually means that the syntax of your connection URL isn't correct for the given driver. The good news in that case is that the driver .class was picked up by the class loader.
Were you going to create a connection with a DriverManager, like you probably did with your app, or were you going to be ambitious and try to set up a connection pool?
I've tried researching how to use the DataSource method of connecting to a database but never could find out how. I know that a DataSource is first configured and registered to JNDI in an application that is separate from the user application, and all the user application will do is retrieve it using JNDI. What I don't understand is where the DataSource is configured. Is it automatically registered when I turn on MySQL, do I need to download another application to register it, or do I make a new class that will do that for me?
You usually have a Java EE app server like Glassfish, WebLogic, JBOSS, Tomcat, or Jetty have a JNDI provider that you should be using for the lookup.
Here's how you do it with Oracle.
Here's how you do it with MySQL.
The JDK 6 javadocs say that a basic DataSource can supply a connection if your driver has such an implementation. I would recommend looking at the Connector-J docs to see if you can do it without JNDI lookup services.