eclipse提示Connection cannot be resolved to a type

eclipse提示Connection cannot be resolved to a type

问题描述:

各位大侠好,本人刚初学java,请大侠帮看一下以下代码在运行时为什么报错,请给上具体解决方法(最好附上图),谢谢!

package com.sp;
//Ctrl+shift+o 以下import就出来了
import java.beans.Statement;
import java.sql.DriverManager;
import java.sql.ResultSet;
import com.sun.jdi.connect.spi.Connection;

//jdbc_odbc桥连接方式
public class TestOra {

public static void main(String[] args) {
    // TODO Auto-generated method stub
 try {
    //1.加载驱动
     Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    //2.得到连接
     Connection ct = DriverManager.getConnection("Jdbc:odbc:testsp","system","111111")
    //从下面开始和SQL SERVER一样
    Statement sm = ct.createStatement();
    ResultSet rs=sm.executeQuery("select * from emp");
    while (rs.next()) {
        //打印内容
        System.out.println("用户名:"+rs.getString(2));
    }
        
} 
    catch (Exception e) {
    e.printStackTrace();
    // TODO: handle exception 异常
}
}

}

在eclipse运行时报错提示如下:
Exception in thread "main" java.lang.Error: Unresolved compilation problems:
Connection cannot be resolved to a type
Syntax error, insert ";" to complete LocalVariableDeclarationStatement
Statement cannot be resolved to a type

at TestMyOracle/com.sp.TestOra.main(TestOra.java:17)

img

在Connection ct = DriverManager.getConnection("Jdbc:odbc:testsp","system","111111")语句改为
Connection ct = DriverManager.getConnection("Jdbc:odbc:testsp","system","111111");
少了分号;你是什么版本的jdk哦,1.8以后的jdk默认不能这样连接数据库了。

img
导包错误 后面缺少分号。