使用select语句的条件查询,需要用到where子句。

 package qddx.JDBC;
import java.sql.*;
public class QueryById { public bbsVo QuerybbsVoById(int id){
bbsVo vo = null;
Connection conn = null;
PreparedStatement pst = null;
ResultSet rs = null;
try{
conn = JDBC_Connection.getConnection();
pst = conn.prepareStatement("select * from article where id=?");
pst.setInt(1, id);//设置条件id
rs=pst.executeQuery();
while(rs.next()){//结果集存在则进行遍历
vo = new bbsVo();
vo.setId(rs.getInt("id"));
vo.setPid(rs.getInt("pid"));
vo.setRootid(rs.getInt("rootid"));
vo.setCont(rs.getString("cont"));
vo.setPdate(rs.getTimestamp("pdate"));
vo.setIsleaf(rs.getInt("isleaf"));
vo.setTitle(rs.getString("title")); }
}catch(SQLException e){
e.printStackTrace();
}finally{
JDBC_Connection.free(rs, conn, pst);
}
return vo; }
public static void main(String[] args) {
// TODO Auto-generated method stub
QueryById byid = new QueryById();
int id = 3;
bbsVo vo = byid.QuerybbsVoById(id);
if(vo!=null){
System.out.print("id\t");
System.out.print("pid\t");
System.out.print("rootid\t");
System.out.print("title\t\t");
System.out.print("cont\t");
System.out.print("pdate\t");
System.out.print("isleaf\t");
System.out.println();
System.out.print(vo.getId()+"\t");
System.out.print(vo.getPid()+"\t");
System.out.print(vo.getRootid()+"\t");
System.out.print(vo.getTitle()+"\t");
System.out.print(vo.getCont()+"\t");
System.out.print(vo.getPdate()+"\t");
System.out.print(vo.getIsleaf()+"\t");
}else{
System.out.println("id为"+id+" 的用户不存在");
}
} }

JDBC查询指定条件的数据的更多相关文章

  1. Oracle数据库的闪回操作(查询指定时间的数据、恢复数据)

    通过DELETE删除数据后相当于放入回收站,一般情况下可以找回:通过UPDATE更新数据后数据库也会保留数据快照.闪回就是恢复指定时间的数据快照以达到恢复数据的目的.根据步骤一查询出数据快照,恢复数据 ...

  2. oracle通过query导出指定条件的数据

    通过下面的方式oracle可以导出指定了条件的数据: exp mixcoaldb/mixcoaldb@server tables=(shengcssjk) query=\"where to_ ...

  3. JDBC查询数据库中的数据

    只用JDBC技术查询表中的全部内容时,需要使用查询全部的SQL语句,把查询结果放到List集合中. package qddx.JDBC; import java.util.*; import java ...

  4. 如何使用JDBC查询指定的记录

    //连接数据库 public class JdbcDao {    private Connection conn=null;    private String strSql=null; publi ...

  5. MySQL查询指定时间的数据

    user_event :用户事件表 create_time :表中存储时间的字段 #获取当月数据 SELECT * FROM user_event WHERE DATE_FORMAT(create_t ...

  6. MySQL通过POIN数据类型查询指定范围内数据

    情况一: 数据库:只有point类型的location字段 实体类:有经纬度字段(double).originLoction字段(存放string类型的数据库location字段:POINT(123. ...

  7. 微信小程序云开发-数据库-查询满足条件的数据

    一.查询价格大于10的商品 1.wxml文件 2.js文件 where条件语句:.where({price:db.command.gt(10)}) 3.查询结果 二.查询价格大于等于10的商品 js文 ...

  8. MongoDB 用MongoTemplate查询指定时间范围的数据

    mongoDB大于小于符号对应: > 大于 $gt< 小于 $lt>= 大于等于 $gte<= 小于等于 $lte 要查询同一个时间多个约束可能出现的error: org.sp ...

  9. mongodb morphia删除数组中指定条件的数据

    先看mongodb操作: db.test.update({"msgid":170},{"$pull":{"msg":{"comti ...

随机推荐

  1. 一个无聊的python + opencv 示例

    opencv不用多说,先推荐一个给力的教程: https://opencv-python-tutroals.readthedocs.io/en/latest/py_tutorials/py_tutor ...

  2. Anagrams

    这题Leetcode上面的描述不清楚.怎么也得举两个例子吧,不然谁懂? 题目的意思是,给定一些字符串,比如["abc","cba","bac" ...

  3. iOS 页面显示在键盘之上

    美丽又可爱的UED妹子文晓的给我提了一个问题,就是在键盘升起的时候,添加的加载页面(loading)被键盘挡住了. 看到问题之后我就想到了问题的所在,因为以前我可敬可爱的领导给我们科普过,说UIAla ...

  4. 学习git config配置文件

    设置 git status的颜色. git config --global color.status auto 一.Git已经在你的系统中了,你会做一些事情来客户化你的Git环境.你只需要做这些设置一 ...

  5. 【CMD】

    1.dir 2. set (不带参数) 查看环境变量. SET [variable=[string]] variable  指定环境变量名. string    指定要指派给变量的一系列字符串. 3.

  6. java基础知识--CLASSPATH

    如果在一个类中用到了另外一个类(new了一个新对象). package com.xxx.xxx; public class Cat { } //下面是另外的文件 public class Dog { ...

  7. 小型资源管理器,IO操作,读取和写入文件和目录的常用操作

    解决方案: 小总结: 用IO流,的file,DirectoryInfo的方法绑定Treeview控件上和删除,读取, 可以熟练掌握一下IO流 主页面: private void Form1_Load( ...

  8. c#缓存介绍(转)

    缓存主要是为了提高数据的读取速度.因为服务器和应用客户端之间存在着流量的瓶颈,所以读取大容量数据时,使用缓存来直接为客户端服务,可以减少客户端与服务器端的数据交互,从而大大提高程序的性能. 本章从缓存 ...

  9. 理解python的with语句

    Python’s with statement provides a very convenient way of dealing with the situation where you have ...

  10. Django01

    1.创建django project 2.创建app 在一个project下可以创建多个app,比如运维系统这个project下面包含监控app.cmdb app等等,这些app共享project里的 ...