In jdbc type 4 connection “driver” has been registered but connection has some error i.e.
Connection con=DriverManager.getConnection("jdbc:oracle:@localhost:1521:XE","system","manager");
error: -incompatible types,found:- java.sql.connection, required :Connection
import java.sql.*;
class A
{
public static void main(String args[])
{
try
{
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection con=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:XE","system","manager");
Statement stmt= con.createStatement();
ResultSet rset=stmt.executeQuery("Select * from emp");
while(rset.next())
{
System.out.println(rset.getInt(1)+"\t"+rset.getString(2)+"\t"+rset.getString(3)+"\t"+ rset.getFloat (4));
}
con.close();
}
catch(Exception e)
{
System.out.println(e);
}
}
}
If I understood correctly, this error message is a compiler error message. It means that your code is in the default package, and you have a class in this default package which is named Connection.
DriverManager.getConnection(...)returns a java.sql.Connection. Useor rename your own Connection class to something else.
And don’t ever use the default package. It leads to all sorts of problems and should be avoided. Always put your classes in a package of yours.