请教:同一包中类的继承问题
一个文件中的类继承另一个文件中的类,但两个文件在同一个自定义的包中,
没有用import的时候说找不到所继承的类,写了个Import语句似乎又是错误的,不知道该怎么改?
程序如下:
dbcon.java
package beans;
import java.sql.*;
public class dbcon
{
Connection con;
public dbcon()
{
}
public Connection getConnection()
{
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con=DriverManager.getConnection("jdbc:odbc:shopdb","","");
}
catch (Exception e)
{
System.out.println(e.toString());
con=null;
}
return con;
}
};
dbexecute.java
package beans;
import java.sql.*;
public class dbexecute extends dbcon
{
private Connection con;
private Statement sql;
private ResultSet rs;
public dbexecute()
{
con=super.getConnection();
sql=null;
rs=null;
}
public boolean exeUpdate(String sqlstr) //执行更新操作
{
try
{
sql=con.createStatement();
sql.executeUpdate(sqlstr);
return true;
}
catch (Exception e)
{
System.out.println(e.toString());
return false;
}
}
public ResultSet exeQuery(String sqlstr) //执行查询操作
{
try
{
sql=con.createStatement();
rs=sql.executeQuery(sqlstr);
}
catch (Exception e)
{
System.out.println(e.toString());
rs=null;
}
return rs;
}
}
错误提示:
E:\JSP\myshop\WEB-INF\classes\beans>javac dbexecute.java
dbexecute.java:5: cannot find symbol
symbol: class dbcon
public class dbexecute extends dbcon
^
dbexecute.java:13: cannot find symbol
symbol : variable super
location: class beans.dbexecute
con=super.getConnection();
^
2 errors
E:\JSP\myshop\WEB-INF\classes\beans>
------解决方案--------------------
E:\JSP\myshop\WEB-INF\classes\beans>javac dbcon.java 生成dbcon.class
然后
E:\JSP\myshop\WEB-INF\classes\beans>javac -classpath E:\JSP\myshop\WEB-INF\classes dbexecute.java 生成dbexecute.class