java 类型不匹配:无法从连接转换为连接
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6126900/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Type mismatch: cannot convert from Connection to Connection
提问by tejas26389
I want JDBC connection to MSaccess. But
我想要到 MSaccess 的 JDBC 连接。但
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 -
我在 jsp 中使用 Servlet 和 jsp -
Organization Name: <input type="text" name="Organization_name" ><br>
i want when Organization_name entered it will be add it in my access databasei have tried but i m facing following problem
我想在输入 Organization_name 时将其添加到我的访问数据库中我已经尝试过但我面临以下问题
Connection con = DriverManager.getConnection("jdbc:odbc:access");
it gives Type mismatch: cannot convert from Connection to Connection
它导致类型不匹配:无法从连接转换为连接
回答by Jigar Joshi
you need Connection
from java.sql
it seems you have imported a wrong class
你需要Connection
从java.sql
它看来你导入了一个错误的类
and getConnection()
needs complete jdbc URL
.
并且getConnection()
需要完整的 jdbc URL
。
In very simple words your code should have following imports
用非常简单的话来说,您的代码应该具有以下导入
import java.sql.Connection
import java.sql.Connection
回答by Costis Aivalis
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.
Northwind 是 Access 中示例数据库的名称。使用你拥有的任何东西。
回答by Ramesh PVK
This could be an classloader issue. The object created is from the different classloader and is referred in another classloader.
这可能是类加载器问题。创建的对象来自不同的类加载器,并在另一个类加载器中引用。
回答by Richard H
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.
Connection
返回的对象getConnection()
与Connection
您在类文件顶部的包导入中引用的类不同。