我想把数据库中mycalc表中价格是4000-5000的产品查询出来?

来源:百度知道 编辑:UC知道 时间:2024/06/08 15:18:46
表mycalc
ID NAME PRICE
01 笔记本 5600
02 台式机 4000
03 HP笔记本 4500
查询出来后输出到JTable中,如何做到?谢谢!
Connection con;
Statement stmt;
ResultSet rs;

String source="jdbc:odbc:productok";
String user="";
String password="";

int price1=Integer.parseInt(jbx1.getItemCount());
int price2=Integer.parseInt(jbx2.getItemCount());

try{

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con=DriverManager.getConnection(source,user,password);
stmt=con.createStatement();
rs=stmt.executeQuery("SELECT * from product where price<=price1 and price>=price2");
while(rs.next()){
id=rs.getInt(1);
uname=rs.getString(2);
uprice=rs.getString(3);
insert into tab(SELECT * from product where price<=price1 and price>=price2));

select * from mycalc where price<=5000 and price>=4000

between and函数也可以,我主要是不知道你的数据库是不是支持
JTable表结构不知道,就没办法给你插,如果是完全一样的结构直接
insert into JTable select * from mycalc where price<=5000 and price>=4000
就可以了

使用模糊查询语句