嗨,我正在開發一個系統在java中我想獲取我的表中存在的所有記錄的計數我嘗試了很多,但它給了我例外 例外是: - java.sql.SQLException:驅動程序不支持此功能如何從java訪問JDBC ODBC數據庫中的行計數
這是我的代碼如下。
import java.sql.*;
import javax.swing.JOptionPane;
import net.proteanit.sql.DbUtils;
public class myfram2 extends javax.swing.JFrame {
Connection con;
PreparedStatement ps;//I have also tried Statement but it give me exception that:
//Column not found
public myfram2() {
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con= con=DriverManager.getConnection("jdbc:odbc:student");
JOptionPane.showMessageDialog(rootPane,"Connection succeed");
}catch(Exception ex){
ex.printStackTrace();
}
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
ResultSet rsc;
try{
//Here i am using sql count method and also tried max but it doesn't work
String sqcount="Select count(stdid)from record";
ps=con.prepareStatement(sqcount);
rsc=ps.executeQuery(sqcount);
if(rsc.next()){
String getc= rsc.getString("count(stdid)");
searchtx.setText(getc);
}
}
catch(Exception ex){
ex.printStackTrace();
}
}
上線,你得到的異常? – Abubakkar 2013-03-13 05:19:34
on count方法,查詢正確但驅動程序不支持count max或sum方法,是否有其他驅動程序可用於訪問數據庫連接 – 2013-03-13 05:40:26