
正文
java更新商品信息代码 java如何更新
提示:扫一扫查出行【扫一扫了解最新限行尾号】
复制提示
点击一个按钮之后让某个商品在数据库中的状态改变,这个功能java怎么实现?是在数据库中操作还是在代码中?
java中获取到商品的状态后,然后在java代码中拼写一条更新的SQL语句,利用jdbc执行以下这条语句就可以了。
for example:
获取连接。。
int flag = 10;
String updateSql = "update table set xxcolumn=" + flag + " where id=3";
statement st = conn.createStatement();
st.executeUpdate(sql);
关闭连接。。。。。。
相关问答
Q1: 数据库如何用java写超市购物程序?
要使用Java编写超市购物程序,您需要使用Java数据库编程技术来连接到您的数据库并执行相关的数据库操作。在Java中,您可以使用JDBC(Java数据库连接)API来连接到数据库并执行SQL语句。例如,您可以使用JDBC API来执行以下操作:
创建数据库连接
执行增删改查(CRUD)操作
提交或回滚事务
执行存储过程和函数
查询数据库元数据
此外,您还可以使用Java的面向对象编程技术来封装数据库操作,以便更方便地在您的程序中使用。例如,您可以创建一个类来表示超市商品,并定义一些方法来执行商品的增删改查操作。这样,您就可以在程序中通过调用这些方法来简单地完成对数据库的操作,而不需要编写复杂的SQL语句。
Q2: 求用java写的类,能够存放商品名称,价格,数量,而且商品名称是唯一的,可以往里面增加新商品信息
private String name;
private double price;
private int number;
set name的时候加个判断 如果商品名存在,则不增加商品信息调更新商品信息.
可以在页面中留一个刷新按钮,每次刷新执行检查check()方法,如果商品number为0,则delete商品所有信息.
需要JDBC的知识不懂留言.
Q3: Java使用字符串生成器来保存购物车中的商品信息,并能实现商品信息的添加、删除以及修改等功能
public class Cart {
public StringBuilder data;
public float total;
public Cart(){
data=new StringBuilder();
}
public void buy(Goods g){
g.gtotal=g.gnum*g.gprice;
total=total+g.gtotal;
data.append("[");
data.append(g.gname+"|");
data.append(g.gprice+"|");
data.append(g.gnum+"|"); //还是竖线看着方便
data.append(g.gtotal);
data.append("]");
}
public void delete(Goods g){
int s=data.indexOf(g.gname);
int e=data.indexOf("]", s);
data.delete(s-1, e+1);
total=total-g.gtotal; //删除商品 java更新商品信息代码,需要修改总额
}
public void update(Goods g){
data.replace(3, 10, "["+g.gname+"|"+g.gprice+"|"+g.gnum+"|"+g.gtotal);
}
public void show(){
System.out.print("总计金额java更新商品信息代码:" + total + " ") ;
System.out.println(data);
}
}
//Excute类里有点小错误java更新商品信息代码,
//总觉得update方法 不对头,你想怎么做java更新商品信息代码?
Q4: java 商品 系统 代码
package entity;
public class Market {
private int id;//id
private int num;//数量
private String goods;//商品
private double price;//价格
public Market(int id, int num, String goods, double price) {
super();
this.id = id;
this.num = num;
this.goods = goods;
this.price = price;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public int getNum() {
return num;
}
public void setNum(int num) {
this.num = num;
}
public String getGoods() {
return goods;
}
public void setGoods(String goods) {
this.goods = goods;
}
public double getPrice() {
return price;
}
public void setPrice(double price) {
this.price = price;
}
public double calc( ){
double sum=price*num;
System.out.println("您消费共计:"+sum+"¥");
return sum;
}
}
package test;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
import entity.Market;
public class Test {
private static MapInteger,Market goods=new HashMapInteger, Market();
public static void main(String[] args) {
System.out.println("-------超市计价系统-------");
String goods1="可口可乐";
String goods2="爆米花";
String goods3="益达";
printTable("编号","商品","价格");
printTable("1",goods1,"3.0¥");
printTable("2",goods2,"5.0¥");
printTable("3",goods3,"10.0¥");
goods.put(1, new Market(1, 1, goods1, 3.0));
goods.put(2, new Market(2, 1, goods2, 5.0));
goods.put(3, new Market(3, 1, goods3, 10.0));
Scanner input = new Scanner(System.in);
System.out.println("请输入商品的编号:");
int num = input.nextInt();
System.out.println("请输入商品的数量");
int amount = input.nextInt();
Market market = goods.get(num);
market.setNum(amount);
market.calc();
}
private static void printTable(String row1,String row2,String row3 ) {
System.out.print(row1);
int times=12;
if (row2!="商品") {
times=5;
}
for (int i = 0; i times; i++) {
System.out.print(" ");
}
System.out.print(row2);
for (int i = 0; i 10; i++) {
System.out.print(" ");
}
System.out.print(row3);
System.out.println("\n");
}
}
//测试结果:
-------超市计价系统-------
编号 商品 价格
1 可口可乐 3.0¥
2 爆米花 5.0¥
3 益达 10.0¥
请输入商品的编号:
3
请输入商品的数量
5
您消费共计:50.0¥
Q5: 哪个高手帮我把下列JAVA程序加个 修改商品价格和打印数据的功能。(要最后的代码,有额外加分)哈哈。。。
public class Goods {
private String GoodsNumbers;
private String GoodsName;
private Integer GoodsPrice;
Integer amount;
Goods(){
}
Goods(String GoodsNumbers, String GoodsName ,Integer GoodsPrice,Integer amount){
this.GoodsNumbers=GoodsNumbers;
this.GoodsName=GoodsName;
this.GoodsPrice=GoodsPrice;
this.amount=amount;
}
public String getGoodsNumbers() {
return GoodsNumbers;
}
public void setGoodsNumbers(String GoodsNumbers) {
this.GoodsNumbers = GoodsNumbers;
}
public String getGoodsName() {
return GoodsName;
}
public void setGoodsName(String GoodsName) {
this.GoodsName = GoodsName;
}
public Integer getGoodsPrice() {
return GoodsPrice;
}
public void setGoodsPrice(Integer GoodsPrice) {
this.GoodsPrice = GoodsPrice;
}
public void modifyPrice(Integer price){
this.GoodsPrice=price;
}
public void print(){
System.out.println(" "+GoodsNumbers+" , "+GoodsName+" , ¥"+GoodsPrice+", 数量:"+amount);
}
public static void main(String s[]){
Goods G1 = new Goods();
G1.amount = 111;
G1.setGoodsNumbers("2012325");
G1.setGoodsName("老坛酸菜方便面袋装");
G1.setGoodsPrice(12);
G1.print();
G1.modifyPrice(18);
G1.print();
}
}
加了构造函数,修改钱,打印函数
java更新商品信息代码的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于java如何更新、java更新商品信息代码的信息别忘了在本站进行查找喔。






