javaweb访问数据库,数据库刚添加的条目能马上查询到吗?

javaweb访问数据库,数据库刚添加的条目能马上查询到吗?,第1张

具体你怎么写的我没有看键拿,不过如果是表中增加一条信息的话,什么时候都可以查询的到的,还有就是每厅桐次查询最好都要关闭连接,如果需要再次查询的话重新连接查询就好扮亮坦了,相关的你可以看一下java关于jdbc连接数据库方面的资料。

其实,也就那几步而已:

别忘了,加载jar文件

加载驱动

获得Connection

获得PreparedStatement /PreparedStatement

执行sql语句

处理结果集ResultSet

关闭连接

mport java.sql.Connection

import java.sql.PreparedStatement

import java.sql.ResultSet

import java.util.ArrayList

import java.util.List

import Entity.JIAJU

public class JiaJu {

 public JIAJU selectExe(int shouhinId) {

  JIAJU jia = new JIAJU()

  try {

   Connection con = ConnectionManager.getConnection()

   String sql = "select * from jiaju where shouhinId=?"

   PreparedStatement ps = con.prepareStatement(sql)

   ps.setInt(1, shouhinId)

   ResultSet rs = ps.executeQuery()

   if (rs != null) {

    while (rs.next()) {

     jia.setShouhinId(rs.getInt("shouhinId"))

     jia.setShouhinName(rs.getString("shouhinName"))

     jia.setShouhinColor(rs.getString("shouhinColor"))

     jia.setShouhinPrice(rs.getInt("shouhinPrice"))

     jia.setShouhinPai(rs.getString("shouhinPai"))

     jia.setShouhinShi(rs.getString("shouhinShi"))

     // list.add(jia)

    }

   }

  } catch (Exception e) {

   e.printStackTrace()

  }

  return jia

 }

 public void insertJia(JIAJU jia) {

  try {

   Connection con = ConnectionManager.getConnection()

   String sql = "insert into jiaju 含烂世values(?,?,?,?,?)"

   PreparedStatement ps = con.prepareStatement(sql)

   ps.setString(1, jia.getShouhinName())

   ps.setString(2, jia.getShouhinColor())

   ps.setInt(3, jia.getShouhinPrice())

   历睁ps.setString(4, jia.getShouhinPai())

   ps.setString(5, jia.getShouhinShi())

   ps.executeUpdate()

  } catch (Exception e) {

   e.printStackTrace()

  }

 }

 public List selectJia() {

  List list = new ArrayList()

  

  try {

   Connection con = ConnectionManager.getConnection()

   String sql = "select * from jiaju "

   PreparedStatement ps = con.prepareStatement(sql)

   ResultSet rs = ps.executeQuery()

   if (rs != null) 谈肢{

    while (rs.next()) {

     JIAJU jia = new JIAJU()

     jia.setShouhinId(rs.getInt("shouhinId"))

     jia.setShouhinName(rs.getString("shouhinName"))

     jia.setShouhinColor(rs.getString("shouhinColor"))

     jia.setShouhinPrice(rs.getInt("shouhinPrice"))

     jia.setShouhinPai(rs.getString("shouhinPai"))

     jia.setShouhinShi(rs.getString("shouhinShi"))

        list.add(jia)

    }

   }

  } catch (Exception e) {

   e.printStackTrace()

  }

  return list

 }

 public JIAJU selectbuy(int shouhinId) {

  JIAJU jia = new JIAJU()

  try {

   Connection con = ConnectionManager.getConnection()

   String sql = "select * from jiaju where shouhinId=?"

   PreparedStatement ps = con.prepareStatement(sql)

   ps.setInt(1, shouhinId)

   ResultSet rs = ps.executeQuery()

   if (rs != null) {

    while (rs.next()) {

     jia.setShouhinId(rs.getInt("shouhinId"))

     jia.setShouhinName(rs.getString("shouhinName"))

     jia.setShouhinColor(rs.getString("shouhinColor"))

     jia.setShouhinPrice(rs.getInt("shouhinPrice"))

     jia.setShouhinPai(rs.getString("shouhinPai"))

     jia.setShouhinShi(rs.getString("shouhinShi"))

    }

   }

  } catch (Exception e) {

   e.printStackTrace()

  }

  return jia

 }

  public void updateLou(JIAJU jia){

   try{

    Connection con = ConnectionManager.getConnection()

   String sql = "update jiaju set shouhinPrice=? where  shouhinId=?"

   PreparedStatement ps = con.prepareStatement(sql)  

   ps.setInt(1,jia.getShouhinPrice())

   ps.setInt(2, jia.getShouhinId())

   ps.executeUpdate()

   }catch(Exception e){

    e.printStackTrace()

   }

  }

  public void deleteLou(JIAJU jia){

   try{

    Connection con = ConnectionManager.getConnection()

   String sql = "delete from jiaju where shouhinId=?"

   PreparedStatement ps = con.prepareStatement(sql)

   ps.setInt(1, jia.getShouhinId())

   ps.executeUpdate()

   }catch(Exception e){

    e.printStackTrace()

   }

  }

}

以俯视的视角展示了X和Z轴的图像。红色高亮表示与标准不同的轴。

坐标(coordinates)在数字上反映了玩家在世界中的位置。

坐标基于一个由互相垂直且交于一点(即原点)的三条坐标轴形成的网格,即一个空间直角坐标系。

x轴的正哗携春方向为东,其坐标反映了玩家距离原点在东(+)西(-)方隐仿向上的距离。

z轴的正方向为南,其坐标反映了玩家距离原点在南(+)北(-)方向上的距离。

y轴的正方向为上,其坐标反映了玩家位置的高低程度(从0至255,其中海平面为62),另见海拔高度。

坐标系的单位长度为一个方块长,基于测量方法,每一方块为1立方米。

因此,三条坐标轴形成了右手坐标系(拇指为x轴,食指为y轴,中指为z轴),通过这样可以更为简单地记住各坐标轴。

一个方块的坐标实际上是这个方块的西北下角那一点的坐标,即方块内的坐标向下取整得到的整数坐标。

在游戏中,一个小数坐标通常需要通过向下取整转换乱耐成整数坐标,这个整数坐标称为原坐标的方块坐标。

————————————————

版权声明:本文为CSDN博主「房东家的狗」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。

原文链接:https://blog.csdn.net/weixin_34696006/article/details/114505023


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/bake/11992916.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-20
下一篇 2023-05-20

发表评论

登录后才能评论

评论列表(0条)

保存