java代码根据id查询 java es根据id查询

用JSP如何根据ID查询数据库相关信息并显示

是不是用eclipse内置的浏览器跑的,建议用其他浏览器跑一下代码,eclipse接收到的信息为null,但是其他浏览器能正常显示

成都创新互联公司主要从事网站制作、成都网站设计、网页设计、企业做网站、公司建网站等业务。立足成都服务通江,10余年网站建设经验,价格优惠、服务专业,欢迎来电咨询建站服务:13518219792

java怎么实现对单个数据进行查询啊?比如我想查询客户ID1的所有信息怎么来写语句啊?求告诉,谢了!

select * from table where id=1;

其中*表示查询所有。table表示你要查询id=1的记录所在的数据表

java 程序中,根据唯一字段(IdNumber),查询出sql表(table_a)中相同的数据,并更新这条数据所有字段

update table_a a set a.xx = ..,a.yy = .. where a.IdNumber = ?

纯sql只能一直set完,如果是hql,就可以更新对象,不过也要设值

JAVA中后台获取ID的值来查询相关的东西

输入用户名密码一般表示登录了,自然有登录之后的权限操作才需要获取该用户的ID。那不输入用户名密码自然就类似一般的网页中的游客。针对这类人应该是没有什么具体的操作权限的。

还是说你有个自动登录的功能,在本地上储存了cookie,那么不输入用户名密码的情况下也能从本地获取到帐号密码来查询对应的ID。

你的问题问太笼统了,不太明白具体到底哪里除了什么样的问题。

JAVA servlet中怎么根据JSP页面传来的ID,用hql语句查询主键ID里的信息?

request.setCharacterEncoding("utf-8");

response.setContentType("text/html;charset=utf-8");

PrintWriter out = response.getWriter();

//获取请求参数

int id = Integer.parseInt(request.getParameter("id"));

//调用dao层将这个id的学生找到

StudentDao sd = new StudentDao();

Student s = sd.findById(id);

//将学生对象保存到request范围

request.setAttribute("s", s);

//使用请求转发,让修改页面展示将要被修改的学生信息

request.getRequestDispatcher("update.jsp").forward(request, response);

out.flush();

out.close();

这是servlet里面的内容

public Student findById(int id){

Student s = null;

Connection conn = null;

PreparedStatement pstm = null;

ResultSet rs = null;

String sql = "select * from student where stuid=?";

//获取连接

conn = BaseDao.getConn();

try {

pstm = conn.prepareStatement(sql);

pstm.setInt(1, id);

//执行查询

rs = pstm.executeQuery();

if(rs.next()){

int stuId = rs.getInt("stuid");

String stuName = rs.getString("stuname");

String stuSex = rs.getString("stusex");

int stuAge = rs.getInt("stuage");

String stuBid = rs.getString("stubid");

//先将数据封装到Student对象中

s = new Student(stuId, stuName, stuSex, stuAge, stuBid);

//将对象放入集合

}

} catch (SQLException e) {

e.printStackTrace();

}finally{

BaseDao.closeAll(conn, pstm, rs);

}

return s;

}

//这是写在Dao里面的内容

//这个是BaseDao   加载驱动 获取链接的

public class BaseDao{

//加载驱动

static{

try {

Class.forName("oracle.jdbc.driver.OracleDriver");

} catch (ClassNotFoundException e) {

e.printStackTrace();

}

}

//获取连接

public static Connection getConn(){

Connection conn = null;

try {

conn = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:orcl", "scott", "130130");

} catch (SQLException e) {

e.printStackTrace();

}

return conn;

}

//关闭所有资源

public static void closeAll(Connection conn,Statement st,ResultSet rs){

try {

if(null!=rs){

rs.close();

}

if(null!=st){

st.close();

}

if(null!=conn){

conn.close();

}

} catch (SQLException e) {

e.printStackTrace();

}

}

}


文章名称:java代码根据id查询 java es根据id查询
转载来于:http://myzitong.com/article/hjgcdj.html