小编Eug*_*ene的帖子

java mysql计算行数

我创建了这段代码,允许我计算表格中的行数.但是,我无法返回计数的数字,并显示"无法从结果类型为void的方法返回值".有人能告诉我'我的错误在哪里?非常感谢!

public void num() 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/testdb?"
      + "user=root&password=");

      // Statements allow to issue SQL queries to the database
      statement = connect.createStatement();
      resultSet = statement.executeQuery("select * from testdb.emg");
      int count = 0;
      while (resultSet.next()) {
        count++;
      }  
      return count;
  } catch (Exception e) {
  }
Run Code Online (Sandbox Code Playgroud)

java mysql

5
推荐指数
2
解决办法
6万
查看次数

列数与第1行JAVA mysql的值计数不匹配

我遇到了一个错误,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: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)
Run Code Online (Sandbox Code Playgroud)

这是非常令人沮丧的,因为我一直在修改代码,比如将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 …
Run Code Online (Sandbox Code Playgroud)

java mysql

3
推荐指数
2
解决办法
2万
查看次数

标签 统计

java ×2

mysql ×2