價值數我遇到了一個錯誤,值java.sql.SQLException:列數不匹配,第1行的mysql JAVA
Column count doesn't match value count at row 1
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1073)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3609)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3541)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2002)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2163)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2624)
at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:2127)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2427)
這是超級沮喪,因爲我一直在修改代碼就像改變在所有字符串arg中,但錯誤仍然出現。
public void readDataBase(int val, 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.setInt(1, val);
preparedStatement.setString(2, d1);
preparedStatement.setString(3, d2);
preparedStatement.setString(4, d3);
preparedStatement.setString(5, d4);
preparedStatement.executeUpdate();
preparedStatement = connect
.prepareStatement("SELECT id, Date, Time, Demand, SUPPLY from MAXdb.emcsg");
resultSet = preparedStatement.executeQuery();
writeResultSet(resultSet);
} catch (Exception e) {
throw e;
} finally {
close();
}
}
我的第二類:
public void Csvreader() throws IOException {
try {
// TODO code application logic here
CSVReader reader = new CSVReader(new FileReader("D:/TEST.csv"));
String nextLine[];
int i = 1;
Mysql sen = new Mysql();
while ((nextLine = reader.readNext()) != null) {
try {
sen.readDataBase(i, nextLine[0], nextLine[1], nextLine[2], nextLine[3]);
i = i+1;
} catch (Exception ex) {
Logger.getLogger(Opencsv.class.getName()).log(Level.SEVERE, null, ex);
}
}
} catch (FileNotFoundException ex) {
Logger.getLogger(Opencsv.class.getName()).log(Level.SEVERE, null, ex);
}
}
數據庫: 字段類型整理屬性Null默認額外操作 ID INT(11)否無
日期文本utf8_general_ci否無
時間文本utf8_general_ci否無
需求文本utf8_general_ci否無
供應文本utf8_general_ci
我只是檢查,只有5場有在MySQL – Eugene 2012-01-16 15:52:23
感謝您的幫助!我發現我的錯誤! – Eugene 2012-01-16 15:59:20