Java 无法将数据发送到其他方法

Java 无法将数据发送到其他方法,java,mysql,Java,Mysql,我在将信息从一个类传输到另一个类时遇到问题。例如,我的第二个类文件将读取一个csv文件并将数据提取到数组nextLine[]中。然后将数据传输到另一个阵列d。然后,该函数调用readDateBase,它将接受数组输入d并执行set string函数。但是,我遇到了一个错误,阻止我将数据发送到函数readDataBase(d);我不知道为什么…有人能帮我吗?非常感谢 public void readDataBase(String d1, String d2, String d3, String d

我在将信息从一个类传输到另一个类时遇到问题。例如,我的第二个类文件将读取一个csv文件并将数据提取到数组nextLine[]中。然后将数据传输到另一个阵列d。然后,该函数调用readDateBase,它将接受数组输入d并执行set string函数。但是,我遇到了一个错误,阻止我将数据发送到函数readDataBase(d);我不知道为什么…有人能帮我吗?非常感谢

public void readDataBase(String d1, String d2, String d3, String d4 ) throws Exception   {
try {
// This will load the MySQL driver, each DB has its own driver
Class.forName("com.mysql.jdbc.Driver");
// Setup the connection with the DB
connect = DriverManager
.getConnection("jdbc:mysql://localhost/MAXdb?"
+ "user=root&password=");

// Statements allow to issue SQL queries to the database
statement = connect.createStatement();
// Result set get the result of the SQL query
resultSet = statement
.executeQuery("select * from MAXdb.emcsg");
writeResultSet(resultSet);

// PreparedStatements can use variables and are more efficient
preparedStatement = connect
.prepareStatement("insert into  MAXdb.emcsg values (default,?, ?, ? , ?, ?)");

// Parameters start with 1

preparedStatement.setString(1, d1);
preparedStatement.setString(2, d2);
preparedStatement.setString(3, d3);
preparedStatement.setString(4, d4);

preparedStatement.executeUpdate();

preparedStatement = connect
.prepareStatement("SELECT  Date, Time, Demand, Supply, Price from MAXdb.emcsg");
resultSet = preparedStatement.executeQuery();
writeResultSet(resultSet);
    }
我的第二节课:

public void Csvreader() throws IOException {
try {
// TODO code application logic here

CSVReader reader = new CSVReader(new FileReader("D:/chart.csv"));

String  nextLine[];
Mysql sen = new Mysql();
while ((nextLine = reader.readNext()) != null) {

sen.readDataBase(nextLine[0], nextLine[1], nextLine[2], nextLine[3]);
}


} catch (FileNotFoundException ex) {
Logger.getLogger(Opencsv.class.getName()).log(Level.SEVERE, null, ex);
}

}
readDatabase()方法接受
String[]
作为参数,并向其传递
String

如果您使用Eclipse之类的IDE,IDE将抛出一条错误消息并突出显示该调用,表示该调用无效。(另外,请尝试阅读错误消息!如果您无法理解,请同时发布错误消息。)


注意你的术语。您的错误不是没有捕获异常,而是您的逻辑总是会引发异常。捕获它不会使您的程序运行,它只会导致程序无声地失败。

我使用的是netbeans,它显示sen.readDataBase(nextLine[0]、nextLine[1]、nextLine[2]、nextLine[3]);以错误突出显示。如果存在编译错误,NetBeans还必须在某些“错误”、“问题”或“编译器”视图中显示错误消息(我已经有一段时间没有使用NetBeans了)。找到这个视图,阅读信息,并尝试理解其含义。错误消息旨在被读取。好的……我发现了错误=。=我没有捕获异常。对不起!