When running the Java web service I'm building on Local Host, everything runs smoothly, however when I attempt to run the exact same code on a different host, such as on AWS, it fails.
I have narrowed the cause down to the fact that the database connection driver "oracle.jdbc.driver.OracleDriver" is absent when the application is not hosted locally, which means that the SQL queries are failing to execute for the obvious reason that they aren't being sent anywhere since the connection is failing to open.
How do I build my project such that the driver is included? Everything else should be fine as it runs as expected on localhost, however I can't run the web service locally, it isn't an option.
You should consider the way you are deploying your webservice. I will give you a checklist, so make sure everything is done.
Insert the oracle jdbc driver inside the libraries folder on your app -- you should consider java jvm version you are running, since your deployment environment may be different from your dev/testing environment;
2nd option: insert the oracle jdbc driver inside your container or application server libraries folder;
Add to your $CLASSPATH or %CLASSPATH% environment variable the right option for your oracle jdbc driver
Related
I downloaded the latest Bitnami Jaspersoft (7.1.1) appliance, and when creating a PostgreSQL (JDBC) Data Source to a PostgreSQL via the Jaspersoft web front-end, the "Test Connection" button always fails with an error message "Connection failed". I downloaded the appliance as an OVM, I'm running it as a VirtualBox VM.
To ensure it's not due to networking issues, I installed psql in the appliance (it's a Debian box) to ensure it can actually connect to my PostgreSQL database (it's a separate server), and it connects well via command-line psql, so I assume the problem is a JDBC issue. I also tried opening port-forwarding 5432 via ssh, so that I can connect to my database via localhost.
My question is, how can debug connection problems in Jaspersoft, or identify what is causing the failure? Jaspersoft 7.1.1 appliance comes with MySQL and PostgreSQL JDBC drivers already installed, and I was able to create and successfully test a new Data Source to the local standard MySQL database, so that driver definitely works. I couldn't find any log files that would output any error messages when testing the connection.
The appliance comes with the following JDBC driver: /opt/bitnami/apache-tomcat/lib/postgresql-9.1-903.jdbc4.jar. It also includes the following files:
/opt/bitnami/apps/jasperserver/buildomatic/conf_source/db/postgresql/jdbc/postgresql-9.4-1210.jdbc41.jar
/opt/bitnami/apps/jasperserver/buildomatic/conf_source/db/postgresql/jdbc/postgresql-9.4-1210.jdbc42.jar
/opt/bitnami/apps/jasperserver/buildomatic/conf_source/db/app-srv-jdbc-drivers/postgresql-9.4-1210.jdbc41.jar
/opt/bitnami/apps/jasperserver/buildomatic/conf_source/ieCe/lib/postgresql-9.4-1210.jdbc41.jar
I'm unfamiliar with Tomcat, and although I understand java code, I'm not a full-stack java developer. How can I debug this problem?
After hacking on it for a while, I tried replacing the file /opt/bitnami/apache-tomcat/lib/postgresql-9.1-903.jdbc4.jar with the latest jdbc driver from jdbc.postgresql.org, and restarted the server. This did the trick! I wonder why the latest Jaspersoft Server appliance comes pre-installed with such an old jdbc driver. Also, installing it via the web-based interface as per the documentation didn't work either.
Answering my own question here just in case anyone else gets stuck with the same problem!
Postgresq by default is not allow connection from remote hosts. It possible if you running postgresql and jaspersoft on different hosts.
How to Allow Remote Access to PostgreSQL database
So I created a MySQL DB on amazon running on the same account as my tomcat server, it built and is running correctly but can't connect to the database.
I can access the remote database running the site using tomcat on my computer, and I can access the db through MySQL workbench, but when I deploy and run it I get a 500 whenever the site tries to access the database.
I opened up my security on this database to accept any connection and port(lol), and I checked if the mysql java connector.jar in the WEB-INF/libs file is the latest version. I even tried setting the JDBC connection string to localhost to see if it would pick it up, but no luck.
I think I'm missing something, can anyone think of any reason my website's JDBC can access the remote database server from my machine but not from the amazon tomcat server?
Also, this is a student project I'm building.
Hope this description makes sense, maybe someone can think of something I haven't tried:)
I've being working on a java project using Derbyclient (database locally hosted). I'm done with everything except that when I'm trying the desktop app while I'm not manually connected to the database (from Netbeans), the error in the title pops up and I can't seem to solve it. Thank you for taking the time to read this and help me.
Derby can be run in two modes embedded or server-based. Server-based allows multiple programs to access the same database. Embedded allows your application to run without a server. Your url selects server-based. The connection refused error indicates that the server is not running. Since the server was started within Netbeans it is shutdown when Netbeans is not running.
The options are:
Switch to embedded.
Start the server with a command outside Netbeans.
Just keep Netbeans running.
To switch to embedded see Apache's documentation for deployment options:
Eliminate the "//localhost:1527" from the url.
also see the tutorial "Run SQL using the embedded driver" at https://builds.apache.org/job/Derby-docs/lastSuccessfulBuild/artifact/trunk/out/getstart/index.html
To start the server in a seperate command window see the syntax for derbyrun.jar:
https://builds.apache.org/job/Derby-docs/lastSuccessfulBuild/artifact/trunk/out/getstart/rgsderbyrunjarsyntax.html
I have a small HSQLDB program to test bits of SQL. I am getting this error:
A pre-version 2.0 client attempted to connect. We rejected them.
Yet the only JDBC driver I have is the HSQLDB v2.3 in the most recent download:
hsqldb/lib/hsqldb.jar
I'm using this string to load the JDBC driver:
Class.forName("org.hsqldb.jdbcDriver");
And the connection string is:
connectionStr = "jdbc:hsqldb:hsql://localhost/tmp_db";
user=sa, password=
Default values. My HSQLDB server seems to have started OK with a database as follows:
server.dbname.0=**tmp_db**
server.database.0=file:r:/.data/hsqldb/**tmp_db/tmp**
[Server#372f7a8d]: Database [index=2, id=2, db=file:r:/.data/hsqldb/**tmp_db/tmp**, alias=tmp_db] opened sucessfully in 26 ms.
I'm using Netbeans and when I connect via the Services tab, the database seems to be opening OK. Wouldn't Netbeans be using the same driver? Can I check that?
The big question is how do we specify the version 2 client connection, driver or parameters? Must I get a different JAR for the correct driver?
One last thing. The test program works fine if I use a file based connection, such as:
jdbc:hsqldb:db_file
Frustratingly too, the server connection string seemed to be working earlier today. At least I could drop/create tables while I was making changes.
You must use the same jars (or at least recent, compatible versions) on the client and server.
The error shows you are using the 2.x version jar on the server but a 1.8 jar on the client. Check NetBeans to see if some extension you have loaded has the old driver. You can use the correct jar in your NetBeans project by adding it as a library.
If the error is not from NetBeans, check your application's classpath and make sure you have the latest jar in it.
I made a page using struts. When running on localhost (glassfish) it is working fine.
However, when I copy WAR file to a remote server and run the application from there login form does not work. That means something is wrong when connecting on mysql database.
How could I solve this?
Code snippet:
Connection conn = null;
Statement stmt = null;
try{
InitialContext ctx = new InitialContext();
DataSource ds = (DataSource)ctx.lookup("jdbc/SB");
conn = ds.getConnection();
stmt = conn.createStatement();
ResultSet rs = null;
if(stmt.execute("SELECT * FROM users WHERE username='"+loginform.getUsername()+"' AND geslo=MD5('"+loginform.getPassword()+"') LIMIT 1;"))
{
rs = stmt.getResultSet();
}
rs.next();
Unfortunately I cannot read from the server console. What else should I do to see the exception (remote logging?)?
Thanks on replies.
UPDATE:
- Both locally and remotely GlassFish 3.0.1 is running.
- My working environment is NetBeans 6.9.1.
- Deploying locally is done simply in NetBeans. I just click on the project name and click publish. For remote deployment, admin gave me access to the FTP server where I just copy the WAR file.
- MySQL server is located somewhere else. The point is, it is accessible from the localhost web application but not from the same remote web application.
Assuming you have admin rights on the remote server, you need to
Verify that the datasource "jdbc/SB" exists. (Resources / JDBC / JDBC Resources)
Verify that the "poolname" in the datasoucre exists (Resources / JDBC/ Connection Pools)
Open the appropriate connection pool and click on the "ping" button.
If ping fails verify the connection params under the Additional Properties tab.
There could be a dozen other issues as well. You really need to get access to the server log so you see what the specific exception is. It's unlikely it's your code and more likely that the remote server is missing the driver dependency or isn't properly configured (the connection pool an datasource)
Some ideas are
- log to file instead of console
- Print log on your struts page
- maybe you don't have grants or firewall problem to access DB
I'd bet that you don't have authority to access the DB...
Try this as a test... install the MySQL client on another machine and then connect to the MySQL server from there.
If that fails then:
Say you log in with:
User: test
Password: password
Then open the Mysql client and enter:
use nameOfDatabase;
GRANT ALL ON nameofDatabase.* TO 'userName'#'ipaddressOfServerOrDNSName';
That should do it.
There are other ways to give access see http://dev.mysql.com/doc/refman/5.1/en/grant.html
Are you sure your database is setup correctly on your remote server? It sounds like maybe a firewall issue.
Unfortunately I cannot read from the server console.
If you have shell access to the remote server, the solution is simple:
Change the logging configs so that your webapp logs to a file instead of / as well as the console.
Login and read the file.
(Indeed, if you were using Tomcat, stuff written to System.out / System.err is written to a file anyway. Maybe this is true for Glassfish also.)
If you don't have shell access, you may have to modify your webapp to provide an extra page that can be used to download or view the log file from your web browser. If you have to resort to this, pay attention to the obvious security concerns.
This is my weg (wild eyed guess)....
Your local app server has the MySql driver installed. The JDBC resource is also defined correctly. The MySql server is probably running on your localhost. You have developed your app locally in NetBeans.
When you deploy an app from NetBeans onto a local server, the IDE makes sure that server has the DB driver installed. NetBeans cannot do that when you deploy to a remote host. If you use some other deployment method, driver installation is not automagic. It is an easy step to forget.
You can find out if the MySql drive is installed on your server by writing a web app that attempts to load or use one of the classes from the driver jar file. If the access generates an exception, you can probably get something that works by including the MySql drive in your webapp's WEB-INF/lib.
NetBeans also helps folks create and manage their JDBC resource definitions. If you create an app that targets a database on your localhost, the JDBC resource will have localhost as part of the URL. This will work great when the app is deployed onto the same server as the DB server. If the app is moved to another server, the JDBC resource needs to be changed to account for the possibility that the DB server is NOT on the localhost.
If you do not have admin access to the remote server, you will have trouble getting the resources defined. If your remote server was a GlassFish 3.1 domain/instance, you could leverage application scoped resources to get the resources defined for your app.
Regarding access to the log file.
If you are using asadmin to deploy onto the remote server, this command will help you access the server log if you are working with GlassFish v2.x: http://docs.sun.com/app/docs/doc/821-0179/display-log-records-1?l=en&a=view. You can also access the log via the admin console.
If you are using rcp to deploy your app, by copying it into the autodeploy directory of the remote server, you may want to see if you can copy the log onto your local machine.
For example... if your admin told you to deploy using an ftp command like this:
ftp> cd /a/b/glassfish/domains/domain1/autodeploy
ftp> put MyGreatWebapp.war
you may be able to get the log by doing something like this:
ftp> cd /a/b/glassfish/domains/domain1/logs
ftp> get server.log
Experiment....