如何统计数据库里表的行数? 什么意思,用count不就行了吗 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 if(st.next()){lyou.setText(st.toString());} 。。应该是st.getInt(1) st.getInt,取到行有好多方法的select count(*) from tableselect top 1 id from table order by id desc select count(*) as count from table int counter = 0;while(st.next()){counter++; ........... } 语句应该没有错只是我如果把得到的结果传到 lyou(JLabel lyou=new JLabel("")) 中怎么样才能够?上面是我是这样写的:if(st.next()){ lyou.setText(st.toString());}//结果是出来了,可是好像出来一大堆...像这样"sun.jdbc.odbc.JdbcOdbcDriver@def3"这样的东东...我知道表中只有4条记录,可是怎么样它才给我出来这个"4"啊.... st是你的一个resultset对象。你把它显示出来当然是乱码。你应该这样int counter = 0;while(st.next()){counter++;} 然后lyou.setText(counter+""); 如果你要使用int counter = 0;while(st.next()){counter++;}lyou.setText(counter+"");就必须改变String sSQLu="Select 姓名 from User";这样应该就可以了。 import javax.swing.*;import java.awt.*;import java.sql.*;import java.io.*;public class aa extends JFrame{ public Connection conn; public Statement state; private JPanel jp=new JPanel(); private JLabel lyou=new JLabel(""); public aa(){ super("abcd"); setBounds(300,200,200,200); jp.add(lyou); try{ Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); String su="jdbc:odbc:driver={Microsoft Access DriVer (*.mdb)};DBQ=lga.mdb"; conn=DriverManager.getConnection(su,"",""); state=conn.createStatement(); String sSQLu="Select 姓名 from User"; ResultSet st=state.executeQuery(sSQLu); int counter = 0; while(st.next()){ counter++;} lyou.setText(counter+""); state.close(); conn.close();} catch(Exception e){} et ei=new et(); this.addWindowListener(ei); this.setContentPane(jp);} public static void main(String[] args){ aa d=new aa(); d.show(); }} 要去循环真笨!!String sSQLu="Select count(姓名) from User"; ResultSet st=state.executeQuery(sSQLu); if(st.next()){lyou.setText(String.value(st.getInt(1)));} Integer是引用类型不 刚接触,求解答,错在哪? 关于IO流 关于百度地图中的代码 !!!!跪求!!! the newer:swt/jface(译自swt in action) windows xp 上JNI写文件的效率为何很低? 几个笔试题,大家帮忙看看!! 谁有java编程思想2每章后面的习题答案啊???? 关于applet,请教!!! 数组参数的使用问题 java.endorsed problem 请教高手
。。应该是st.getInt(1)
取到行有好多方法的
select count(*) from table
select top 1 id from table order by id desc
while(st.next()){counter++;
...........
}
上面是我是这样写的:
if(st.next()){
lyou.setText(st.toString());}
//结果是出来了,可是好像出来一大堆...像这样"sun.jdbc.odbc.JdbcOdbcDriver@def3"这样的东东...
我知道表中只有4条记录,可是怎么样它才给我出来这个"4"啊....
你应该这样int counter = 0;
while(st.next()){counter++;} 然后lyou.setText(counter+"");
int counter = 0;
while(st.next()){counter++;}
lyou.setText(counter+"");
就必须改变
String sSQLu="Select 姓名 from User";
这样应该就可以了。
import java.awt.*;
import java.sql.*;
import java.io.*;public class aa extends JFrame{
public Connection conn;
public Statement state;
private JPanel jp=new JPanel();
private JLabel lyou=new JLabel("");
public aa(){
super("abcd");
setBounds(300,200,200,200);
jp.add(lyou);
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String su="jdbc:odbc:driver={Microsoft Access DriVer (*.mdb)};DBQ=lga.mdb";
conn=DriverManager.getConnection(su,"","");
state=conn.createStatement();
String sSQLu="Select 姓名 from User";
ResultSet st=state.executeQuery(sSQLu);
int counter = 0;
while(st.next()){
counter++;}
lyou.setText(counter+"");
state.close();
conn.close();}
catch(Exception e){}
et ei=new et();
this.addWindowListener(ei);
this.setContentPane(jp);} public static void main(String[] args){
aa d=new aa();
d.show();
}
}
String sSQLu="Select count(姓名) from User";
ResultSet st=state.executeQuery(sSQLu);
if(st.next()){lyou.setText(String.value(st.getInt(1)));}