Not getting connection properly - java

I'm trying to make a Java Swing front end and back end as Oracle Thin I am getting this error:
java.lang.ClassNotFoundException: oracle.jdbc.OracleDriver
on the following statement
Class.forName ("oracle.jdbc.OracleDriver");
I've copied the driver jdbc6.jar,and classes12.jar in lib. I am using Oracle 10g and my JDK is 1.8.

Could be one or both of these:
ojdbc6.jar isn't in your class path. (notices you saids jdbc6.jar missing o)
Your jdbc url isn't correct. Please provide some of your codes.

Related

Getting the "no suitable driver found for..." JDBC error, but I already added the jar to my Eclipse path

Basically I'm trying to connect my eclipse to JDBC, I've already add the external path of jdbcsql to my eclipse.
When I rand my java in code in eclipse, so far I have this error:
Exception in thread "main" java.sql.SQLException: No suitable driver found for jdbc:microsoft:sqlserver://HOST:1433;DatabaseName=MASTER
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at insertion.insert_values(insertion.java:12)
line 12 revers to this line:
con = DriverManager.getConnection("jdbc:microsoft:sqlserver://HOST:1433;DatabaseName=MASTER","sa","password");
I uses my SA account for JDBC, and this part of my Java code that connect my eclipse to the JDBC driver:
Connection con = null; PreparedStatement statement = null; //to take care of the sql statements to be run
//Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
con = DriverManager.getConnection("jdbc:microsoft:sqlserver://HOST:1433;DatabaseName=MASTER","sa","ronpaul");
Is the problem with my URL or my code syntax, or is it I didn't add the external jar to my eclipse the right way?
I already added the last JDBC driver to my java package path, so what's causing the error? The line 12 has a code syntax error maybe?
Is the problem with my URL
Yes. Microsoft's JDBC Driver for SQL Server uses the URL prefix
jdbc:sqlserver://...
not
jdbc:microsoft:sqlserver://...
See the MSDN document Building the Connection URL for details.

Pentaho SQL (Native) connection error

I'm running a couple of SQL connections from a Job. They are all working with the sqljdbc4.jar, but when I run them with MS SQL Server Native (which was by default) instead of MS SQL Server - they fail with this error:
Error connecting to database [xxx_zxxxx] : org.pentaho.di.core.exception.KettleDatabaseException:
Error occured while trying to connect to the database
Error connecting to database: (using class com.microsoft.sqlserver.jdbc.SQLServerDriver)
Java Runtime Environment (JRE) version 1.7 is not supported by this driver. Use the sqljdbc4.jar class library, which provides support for JDBC 4.0.
org.pentaho.di.core.exception.KettleDatabaseException:
Error occured while trying to connect to the database
at org.pentaho.di.core.database.Database.normalConnect(Database.java:427)
at org.pentaho.di.core.database.Database.connect(Database.java:361)
.................
Caused by: org.pentaho.di.core.exception.KettleDatabaseException:
Can this be caused by the new JDK_1.8 I've installed? How to resolve this issue?
Thank you.
I found a work-around solution that worked just fine in my case. Just remove the sqljdbc.jar and leave only sqljdbc4.jar in my file system. Also added only sqljdbc4.jar to the System variables > path

Please let me know any MySQL version which works with jdk 1.7

I Installed JDK 1.7 and tried to connect to different MySQL database and Connector/J versions. But every time, I'm getting the following error when loading the driver:
Exception in thread "main" java.lang.ExceptionInInitializerError
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:186)
at jdbc.JDBC.main(JDBC.java:24)
Caused by: java.lang.RuntimeException: Uncompilable source code - com.mysql.jdbc.NonRegisteringDriver is not abstract and does not override abstract method getParentLogger() in java.sql.Driver
at com.mysql.jdbc.NonRegisteringDriver.<clinit>(NonRegisteringDriver.java:69)
... 3 more
Which MySQL driver version is compatible with JDK 1.7?
The exception message says this:
"Caused by: java.lang.RuntimeException: Uncompilable source code - com.mysql.jdbc.NonRegisteringDriver is not abstract and does not override abstract method getParentLogger() in java.sql.Driver"
I think that the problem is that you (or someone else) have/has attempted to build the JDBC driver from source code and not noticed that there were compilation errors, and assembled the resulting broken ".class" files into a JAR file.
The standard Connector/J driver JAR files from the MySQL website should work with Java 7. Certainly, I've never experienced any problems like this with them.
I'm more inclined to believe the evidence that I can see in the Exception message than your assurance that everything is "perfect":
Are you sure that you are using a Connector/J JAR file that you downloaded from the MySQL Website?
Did you check that MD5 checksum to make sure that you got the real thing?
If you built from source, did you read the stuff in the docs/readme.txt about the JRE versions required to build correctly?
Do you have some other (broken) copy of the drivers on your application's classpath?
"Caused by: java.lang.RuntimeException: Uncompilable source code -
com.mysql.jdbc.NonRegisteringDriver is not abstract and does not override
abstract method getParentLogger() in java.sql.Driver"
The method getParentLogger() was introduced to the Driver interface in Java 1.7.
Find a MySQL driver that supports Java 1.7 or switch back to Java 1.6.
Edit: Additional info:
I tested JDK 1.7.10 and a driver Jar named: mysql-connector-java-5.1.6-bin.jar
Using the following code:
public static void main(String[] args) throws ClassNotFoundException,
InstantiationException, IllegalAccessException, SQLException {
System.out.println("Java version: "
+ System.getProperty("java.version"));
Driver driver = (Driver) Class.forName("com.mysql.jdbc.Driver")
.newInstance();
System.out.println("JDBC driver: " + driver.getMajorVersion() + "."
+ driver.getMinorVersion());
Connection connection = DriverManager.getConnection(
"jdbc:mysql://localhost:3306/DBNAME", "user", "pass");
System.out.println("Connection: " + connection.getClass().getName());
}
It gives the following output:
Java version: 1.7.0_10
JDBC driver: 5.1
Connection: com.mysql.jdbc.JDBC4Connection
Possibly you have also a problem with the JDK/JRE Installation. When installing the JDK, it wants to update SQL drivers.
You might give it a try to uninstall and re-install the JDK.

JDBC Driver class not found in Hibernate program

I am making a simple mapping program in hibernate.
I am facing an error:
JDBC Driver class not found: com.mysql.jdbc.Driver
java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
It gives an error on this line:
Session session = HibernateUtil.getSessionFactory().openSession();
hibernate.cfg.xml is correct. In the same configration other program are run. but this program give me error.
What is the reason that it throws this error?
You need to get a MySQL driver and put it on your classpath.
A commonly-used driver is MySQL Connector/J. It can be found here. Extract the package and make the jar available to your application.

Use of BLOB giving "java.lang.ClassNotFoundException: oracle.sql.BLOB" in case of SPRING-Hibernate application in case of ORACLE as a database!

I am using BLOBs in my SPRING-Hibernate application its, giving "java.lang.ClassNotFoundException: oracle.sql.BLOB" in case of ORACLE as a database!
Exactly I am getting following:
Caused by:
org.springframework.dao.InvalidDataAccessApiUsageException: Couldn't initialize OracleLobHandler because Oracle driver classes are not available. Note that OracleLobHandler requires Oracle JDBC driver 9i or higher!
nested exception is java.lang.ClassNotFoundException: oracle.sql.BLOB
You need ojdbc.jar (or similar) on your classpath (this is the Oracle JDBC driver)
Here is a list of drivers, pick the one that suits your environment.
Maybe your OSGI manifest does not export the right packages?

Categories

Resources