I am getting the same total (which is incorrect) for "Count" in code below. If i use "Statement", the total is correct. The incorrect result which is shown on the console is ...
run:
Connection Successful
Members 500
Payment 500
BUILD SUCCESSFUL (total time: 0 seconds)
package preparedstatement2;
import java.sql.*;
public class Main {
public static void main(String[] args) {
Connection conn = SqliteConn.connectDB();
try {
PreparedStatement pst = conn.prepareStatement("Select Count (?) From members");
pst.setString(1, "mem_id");
ResultSet rs = pst.executeQuery();
while (rs.next()) {
int mem_id = rs.getInt(1);
System.out.println("Members " + mem_id);
}
pst.setString(1, "payment");
rs = pst.executeQuery();
while (rs.next()) {
int payment = rs.getInt(1);
System.out.println("Payment " + payment);
}
} catch (SQLException ex) {
ex.getMessage();
}
}
}
edit: the expected output is supposed to be:
Connection Successful
Members 500
Payment 400
BUILD SUCCESSFUL (total time: 0 seconds)