Error while connecting to Oracle DSN using Java - java

I need to develop an application that connects to various DSN's using the Microsoft ODBC drivers. I have developed the application in Eclipse and it seems to work properly. The connection succeeds and I am able to view table data.
However when I export the project to a runnable jar file (using Eclipse) the functionality fails for Oracle. It is unable to establish connectivity with the Oracle connection string. It still works for SQL server but fails in case of Oracle. I'm unable to figure out the cause as the same ODBC drivers are being used for both Oracle and SQL-Server. More mystifying is that it runs properly on Eclipse. Since im using the ODBC drivers I don't believe the problem is because of an external jar file.
The driver is sun.jdbc.odbc.JdbcOdbcDriver and connection string is like jdbc:odbc:oratest;user=fell;password=pass.
I'm getting the following exception
java.sql.SQLException: [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified
at sun.jdbc.odbc.JdbcOdbc.createSQLException(JdbcOdbc.java:6958)
Can you please help me figure what the problem might be?
Thanks in advance,
Fell

Create a System DSN.
java.sql.Connection cn;
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
cn=java.sql.DriverManager.getConnection("jdbc:odbc:dsn_name","user","pass");

Check the classpath in the eclipse project

Related

How to set a MS Access DB (.mdb) in JasperSoft Studio (Eclipse)?

I have a .mdb database and I'm trying to design a report using JasperSoft Studio 6.3.0 (Eclipse plug-in).
In my Java Application I have used the UCanAccess JDBC Driver to build the connection as JDBC-ODBC Bridge is no longer supported in Java 8.
When creating the Data Adapter, I chose "Database JDBC Connection", and then, as UCanAccess is not in the default list of Drivers, I added the .jar file with the UCanAccess Driver.
Screenshot from the Classpath:
Then, I wrote the Driver Class in JDBC Driver (note: the standard action is to choose one of the drivers in the combobox, but as I had to add it manually, I read somewhere in the Internet that I must write it by myself).
Screenshot from the Driver setting:
When I test the connection, it will stay loading forever and will never end.
NOTE: the database has no user/pass. I successfully connected the database to my Java application (using the UCanAccess Driver); my problem is with the connection to the report.
What can I do? Any suggestions? Thanks!
I managed to solve my question by myself. I also had to add the four .jar in UCanAccess-x.x.x-bin>>lib to the Classpath (commons-lang, commons-logging, hsqldb, jackcess)

How could I connect my Eclipse IDE with the Oralce 11g in Windows 8?

I want my java program to handle Oracle SQL queries. For that, I have written the following code.
on running this code it shows the following errors.
I don't know how to connect my Eclipse IDE with the Oracle. How could I connect my Eclipse IDE to the Oracle and how to get rid of these errors? And I don't want to connect to any online oracle servers, I googled and get suggestions for connecting to online servers.
How could I connect my Oracle 11g with my Eclipse Kepler in Windows 8?
Please check below :
Driver version and DB version should be same.
Try login with sqlplus or some clients like Toad, SQL developer.
The number of connections allowed may exceeded, result in TNS listener error, that you may got minus one from read call error in stacktrace. If connections are exceeded kill inactive connections.
Try establishing connection like below
DriverManager.getConnection(DB_URL,USER,PASS);
Above exception your are getting when operating system has some internal environment problem.
I have got same problem with type 4 driver. But type 1 driver not giving this exception. So start using the type 1 oracle driver.
You can check the sid port in tnsnames.ora file which is in below location.
C:\oraclexe\app\oracle\product\10.2.0\server\NETWORK\ADMIN\SAMPLE\tnsnames.ora

Connection to SQLServer2012 with JTDS driver and Windows authentication

I am trying to connect to Microsoft SQLServer 2012 through Java. I have tried using the Microsoft supplied jdbc driver, as well as the jtds driver.
However, whenever i try to load either of the drivers, I get a "No suitable driver found" exception.
The connection URL i have is:
jdbc:jtds:sqlserver://localhost:1433/mineDB;instance=SQLServer2012;integratedSecurity=true;USENTLMV2=true
The driver class name:
net.sourceforge.jtds.jdbc.Driver
I have loaded the jtds.1.3.1.jar file into my classpath system variable, and when trying to use the windows jdbc driver i did the same
EDIT:
Forgot to mention. the driver is called using Class.forName().
Everything is being done on one machine at the moment, and once it is all working i'm going to see if i can get an external database connection working

Exception while connecting to DB2 in java using JDBC

I am trying to connect to a db2 database in Java. Below the driver and the connection string and the driver details i am giving
Class.forName("COM.ibm.db2.jdbc.net.DB2Driver");
String url="jdbc:db2://hostname:portnumber/databasename";
sourceConnection=DriverManager.getConnection(url,"username","password");
But I am getting the below exception
"COM.ibm.db2.jdbc.DB2Exception: [IBM][JDBC Driver] CLI0615E Error receiving from socket, server is not responding. SQLSTATE=08S01"
I also tried changing the connection string to
String url="jdbc:db2:hostname:portnumber/databasename";
Still it is resulting the same exception above while trying to get the Connection.
And i have tried the below option also using JDBC app driver
Class.forName("COM.ibm.db2.jdbc.app.DB2Driver");
DB2DataSource db2ds = new DB2DataSource();
db2ds.setServerName("hostname");
db2ds.setPortNumber(portnumber);
db2ds.setDatabaseName("databasename");
db2ds.setUser("username");
db2ds.setPassword("password");
sourceConnection=db2ds.getConnection();
For the above two connection I used the jar "db2java.jar"
And i have tried using the JCC driver:
Class.forName("com.ibm.db2.jcc.DB2Driver");
String url="jdbc:db2://hostname:portnumber/databasename";
sourceConnection=DriverManager.getConnection(url,"username","password");
For this connection i have added the below jars
1)db2jcc.jar
2)db2jcc_license_cu.jar
This time around I am getting the below error,
"com.ibm.db2.jcc.am.go: [jcc][t4][201][11237][3.57.82] Connection authorization failure occurred.
Reason: Security mechanism not supported. ERRORCODE=-4214, SQLSTATE=28000"
I tried to connect to the same db2 source using "Quest for DB2" tool and the connection was successful.
Am i missing something in the code and is it a problem with DB2 drivers or connection string?
Can someone please guide me.
Thanks in advance.
Cause:
If the DB2® instance where InfoSphere Optim Performance Manager is running has the authentication configuration parameter set to DATA_ENCRYPT, you cannot log in to the web console.
Resolving the problem:
Do the following steps:
On the DB2 instance where Optim Performance Manager is running, set the authentication configuration parameter to SERVER by issuing the following command:
db2 update dbm cfg using authentication server
Restart the DB2 instance and InfoSphere Optim Performance Manager.
For more details visit here.
Your first two attempts were not supposed to work. You're using the JCC driver URL format, so it wouldn't be valid for either "net" or "app" drivers, which are deprecated anyway.
Use the JCC driver (com.ibm.db2.jcc.DB2Driver) and the URL format of "jdbc:db2://hostname:portnumber/databasename" and see this technote for the solution to the "Security mechanism not supported" problem. In short, you need to use a supported JDK.

MySQL Jar works but MSSQL does not?

I don't use the Class.forName(abcde) for my MySQL-java-jdbc code. My code works properly.
All I did was drop the mysql.jar in my lib folder and the code worked.
But, for MSSQL, this does not work and I get the following error:
java.sql.SQLException: No suitable driver found for jdbc:microsoft:sqlserver://localhost:1433
I am using both sqljdbc.jar and sqljdbc4.jar, java 1.6 and MSSQL 2008.
Can you tell me how to find the cause for this problem ?
I think you've got the database connection URL wrong. There should be no microsoft within it. Try jdbc:sqlserver://localhost:1433 instead.
See also the MSDN documentation for the SQL Server JDBC driver.

Categories

Resources