开发者

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 Conn开发者_如何转开发ection

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


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


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.


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.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜