I’m not getting data into mysql
void connectionDB() {
try {
Class.forName(fileReader.getdriver());
String url = "jdbc:mysql://"+ fileReader.gethost() + ":" + fileReader.getDBport() +"/" + fileReader.getdbname();
conn = DriverManager.getConnection(url, fileReader.getusername(),fileReader.getpasswd());
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException se) {
se.printStackTrace();
}
}
public void snmp_mysql(String ipv6Address, String[] resString) {
try {
stat = conn.createStatement();
String sql =
("INSERT INTO Statistics3 VALUES ('" + ipv6Address + "','"
+ dateTime.trim() + "'," + battpercent + ")");
stat.executeUpdate(sql);
stat.close();
System.out.println("updating");
} catch (SQLException e) {
e.printStackTrace();
System.out.println("SQL statement is not executed!");
}
}
The code is not showing any error and it is showing Empty set (0.01 sec) in MySQL. Previously it worked properly and got the output. I didn’t make any changes. I do not know why its not working.
I have taken another class in another project and added some columns to the existing table Statistics3,and used mysql for that class.I didnt make any changes in this class.That doesn’t effect mysql know
While i’m running the project,i’m getting these errors in the middle of the output
java.sql.SQLException: 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:3597)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3529)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1990)
You can explicitly specify the column into which you want to insert data.. As you can see, you can also skip some column..
column1,column2, andcolumn4are columns corresponding to your values –ipv6Address,datetime, andbattpercent.. in your table..So, if you have inserted a column –
column3, then you can just skip it.. It will get the default value as you have set..