日期:2014-05-20  浏览次数:21243 次

为什么同一个包下的类不能引用,编译错误。
两个类ReadDBConfig.java   和   CustomSQL.java,ReadDBConfig.java   编译通过,在JSP中引用也可以用,但CustomSQL.java就是编译出两个错误。

package   qzjz;

import   java.sql.*;
import   java.io.*;
import   java.util.Properties;

public   class   ReadDBConfig   {
//数据库驱动
private   String   driver;
//数据库URL
private   String   url;
//数据库用户名
private   String   user;
//数据库用户密码
private   String   password;

private   Properties   props   =   new   Properties();

public   ReadDBConfig()   {
try{
//读取配置文件
InputStream   in   =   new   FileInputStream( "dbConfig.properties ");
props.load(in);
//读取属性文件的值
driver   =   props.getProperty( "driver ");
url   =   props.getProperty( "url ");
user   =   props.getProperty( "user ");
password   =   props.getProperty( "password ");
//关闭输入流
in.close();
if(driver   ==   null||null   ==   url||null   ==   user||null   ==   password)
System.out.println( "读取属性文件的资料不全。 ");
}   catch(Exception   e)   {
System.out.println( "读取数据库配置失败 ");
e.printStackTrace();
}
}

//属性操作
public   void   setDriver(String   driver)   {
this.driver   =   driver;
}
public   void   setURL(String   url)   {
this.url   =   url;
}
public   void   setUser(String   user)   {
this.user   =   user;
}
public   void   setPassword(String   password)   {
this.password   =   password;
}

public   String   getDriver()   {
return   driver;
}
public   String   getURL()   {
return   url;
}
public   String   getUser()   {
return   user;
}
public   String   getPassword()   {
return   password;
}

//写入数据库配置文件
public   void   writeDBConfig()   {
props.setProperty( "driver ",driver);
props.setProperty( "url ",url);
props.setProperty( "user ",user);
props.setProperty( "password ",password);

try   {
OutputStream   ops   =   new   FileOutputStream( "dbConfig.properties ");
props.store(ops,null);
ops.close();
}   catch(IOException   ioe)   {
System.out.println( "保存数据库配置失败! ");
ioe.printStackTrace();
}
}
}


package   qzjz;

import   java.sql.*;

public   class   CustomSQL   {
private   String   sqlyuju;
private   String   driver;
private   String   url;
private   String   user;
private   String   password;
private   Connection   con;
private   Statement   smt;
private   ResultSet   rst;
private   int   i;

public   void   CustomSQL()   {
ReadDBConfig   readdbconfig   =   new   ReadDBConfig();//就是这句编译出错
driver   =   readdbconfig.getDriver();
url   =   readdbconfig.getURL();
user   =   readdbconfig.getUser();