Openshift Postgresql connection error: - java

Edited: I checked the log file, and the URL message is:
Cannot create JDBC driver of class 'org.postgresql.Driver' for connect URL 'postgresql://adminxxxxxxx:xxxxxxxxx#10.1o.1o.10:5432'
I get the following error with postgres on openshift (9.x)
java.sql.SQLException: No suitable driver
java.sql.DriverManager.getDriver(DriverManager.java:278)
My URL is ${OPENSHIFT_POSTGRESQL_DB_URL}
This exact build works on my local host (different URL, of course), and I can see the openshift jar in the correct place in the war file
Any ideas?

Turns out the URL in the environment variable on Openshift does not work.
See here:
http://mikeski.net/blog/index.php?/archives/17-Postgres-and-JBoss-on-openshift.html

Related

Something unusual has occurred to cause the driver to fail. Heroku postgresql database

I have created a heroku posgresql database and I am trying to connect my Android app to this database. I am using Android Studio for making the Android app. I have used the following code for creating the connection:
try {
Class.forName("org.postgresql.Driver");
Connection db = DriverManager.getConnection(dbUrl);
}
catch(Exception e){
//handles exception
}
When I execute this code I get the following error: Something unusual has occurred tot cause the driver to fail. Please report this exception.
This is the driver I use: posgresql-42.2.12
The heroku database has version 12.2
Android studio has java version 1.8
I am not sure if the driver is in the classpath and I am not sure how to check this. I added the driver to the project this way: app > New > Module > Import .JAR/.AAR Package (here I selected the driver).
To check if the Driver is registered in DriverManager I used this code:
Enumeration<Driver> drivers = DriverManager.getDrivers();
drivers.nextElement().getClass().getName();
This gives: org.postgresql.Driver
To check if the Driver understandes the URL I used this code:
DriverManager.getDriver(dbUrl).getClass().getName();
This also gives org.posgresql.Driver so I think the Driver is registered to the DriverManager and should be able to connect to the database using the URL. I just really don't know why I keep getting an error when I try to connect with the database.
So why does the error occur and how can I resolve the issue?
My first guess would be a malformed connection string. Are you using a proper JDBC URL (i.e. it starts with jdbc:) for dbUrl? Also make sure you include sslmode=require.
In addition, please be aware that the database URL is managed by Heroku and will change under certain circumstances. You can read more about using Heroku Postgres from outside of Heroku in this DevCenter article.

What is the correct procedure for adding SQL Server JDBC to GlassFish 3.1.2

I am setting up a test GlassFish Server to learn NetBeans, Java, GlassFish web application development. I was able to do a basic deployment successfully and am moving on to databases.
I am trying to set up a MS SQL Server connection pool in the GlassFish admin. After configuring the datasource as javax.sql.Datasource and setting the properties, it fails to successfully ping the connection.
When I try to ping the connection, I get this error
Ping Connection Pool failed for SQLDB. Class name is wrong or classpath is not set for :
com.microsoft.sqlserver.jdbc.SQLServerDataSource
It looks like the .jar file isn't being loaded. I have placed the sqljdbc4.jar in the glassfish\modules folder.
What is the correct process for setting up a JDBC connection pool for SQL Server?
In case you are using JRE 7 : use JDBC41
in case you are using JRE 8 : use JDBC42
Unzip the exe from the following link : https://www.microsoft.com/en-us/download/confirmation.aspx?id=54671
Paste the jar in the lib folder of glassfish .
Once done define property under connection pool as URL and pass full qualified connection name as : jdbc:sqlserver://localhost\MSSQLSERVER:1433;databasename=AdventureWorks2016;integratedSecurity=true

ClassNotFoundException MySQL OpenShift

Iam trying to connect my app to the MySQL Back on my OpenShift Account via jdbc. Here my source:
Class.forName("com.mysql.jdbc.Driver");
Connection m_connection = DriverManager.getConnection(url , user , pass);
i´ve added my jdbc_connector.jar to the build path, but if im testing it on localhost or in web i always get an
'java.lang.ClassNotFoundException: com.mysql.jdbc.Driver'
How to solve the problem, where to add the jdbc_connector.jar?
Thanks.
JBDC need you to have a path to the jar for the server you are using in path...
Soooo...
Do not forget to add the path of the connector to the classpath. If the connector name is
mysql-connector-java-5.1.21-bin.jar stored in C:\mysql-connector-java-5.1.21, then
add c:\ mysql-connector-java-5.1.21\mysql-connector-java-5.1.21-bin.jar to the
classpath.
Oh and here is the connector http://dev.mysql.com/downloads/connector/j/

Connection with Sybase

I am new to Sybase ,I'm developing a web application with sybase and jboss, my app connect with the Sybase database. I have put the jconn4.jar in same directory with war file in deployments directory . My config in standalone.xml like this
<connection-url>jdbc:jtds:sybase://<myserver>:<myport>/<mydb></connection-url>
<driver-class>com.sybase.jdbc4.jdbc.SybDriver</driver-class>
<!--<driver-class>net.sourceforge.jtds.jdbc.Driver</driver-class> -->
<driver>jconn4.jar</driver>
and when i use com.sybase.jdbc4.jdbc.SybDriver got the error message
javax.resource.ResourceException: Wrong driver class [class com.sybase.jdbc4.jdbc.SybDriver] for this connection URL [jdbc:jtds:sybase://<myhost>:<myport>/<mydb>
...
when i use net.sourceforge.jtds.jdbc.Driver i got the message
java.lang.ClassNotFoundException: net.sourceforge.jtds.jdbc.Driver from [Module "deployment.jconn4.jar:main" from Service Module Loader]
I don't know what driver-class suitable for driver class jconn4.jar
You are using the driver url of the open source jTDS driver, but you are trying to use the Sybase driver. Use the right JDBC url for the Sybase driver: Check the documentation included with the Sybase driver for details (I can't be more specific because the Sybase documentation is usually hard to find online without access to the support portal). Or switch to jTDS, in which case you need to deploy it as a module to JBoss and reference the right driver module in the config.

Unable to connect SQL database in Netbeans

I am trying to create a simple web application in J2EE.
I am getting the following error:
exception:
javax.servlet.ServletException: javax.servlet.jsp.JspException: Unable to get
connection,
DataSource invalid: "java.sql.SQLException: No suitable driver found for jdbc/qweDS"
root cause:
javax.servlet.jsp.JspException: Unable to get connection, DataSource invalid:
"java.sql.SQLException: No suitable driver found for jdbc/qweDS"
added thee resource, created the connection pool, checked the connection.. enabled the driver.. checked web.xml file and glassfish-resources.xml
Any idea what am I doing wrong. or where to set the driver.
You need to download a suitable JDBC driver depending on your database, then right-click on the project on Netbeans and click Add Library. After that choose the JDBC.jar file you downloaded and try again.
You have notincluded driver jar file. According to your database you have to include driver jar file like in Mysql you have to include mysql-connector-java-(version).jar
You can download from internet

Categories