tejas26389
tejas26389

Reputation: 73

Type mismatch: cannot convert from Connection to Connection

I want JDBC connection to MSaccess. But

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con = DriverManager.getConnection("jdbc:odbc:access");

it gives

Type mismatch: cannot convert from Connection to Connection

what is solution for that?

I m using Servlet and jsp in jsp -

Organization Name:    <input type="text"  name="Organization_name" ><br>

i want when Organization_name entered it will be add it in my access database i have tried but i m facing following problem

Connection con = DriverManager.getConnection("jdbc:odbc:access");

it gives Type mismatch: cannot convert from Connection to Connection

Upvotes: 2

Views: 10964

Answers (4)

Ramesh PVK
Ramesh PVK

Reputation: 15456

This could be an classloader issue. The object created is from the different classloader and is referred in another classloader.

Upvotes: 0

Jigar Joshi
Jigar Joshi

Reputation: 240946

you need Connection from java.sql it seems you have imported a wrong class

and getConnection() needs complete jdbc URL.

In very simple words your code should have following imports

import java.sql.Connection

Upvotes: 5

Costis Aivalis
Costis Aivalis

Reputation: 13728

try this:

import java.sql.Connection;
import java.sql.DriverManager; 

...

try { 
   String username = "";
   String password = "";
   Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
   DriverManager.getConnection("jdbc:odbc:northwind", username, password);
   ...

northwind is the name of the sample database in Access. Use whatever you've got.

Upvotes: 2

Richard H
Richard H

Reputation: 39135

The Connection object that is being returned by getConnection() is not the same Connection class you have referenced in your package imports at the top of your class file.

Upvotes: 0

Related Questions