📄 goodsinfoimplement.java
字号:
package com.test.ps.cart;
import java.io.UnsupportedEncodingException;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import com.test.ps.goods.*;
import com.test.ps.util.DBUtil;
public class GoodsInfoImplement {
Connection conn = null;
Statement stmt = null;
ResultSet rs = null;
public GoodsInfoImplement() {
conn = DBUtil.getConnection();
try {
stmt = conn.createStatement();
} catch (SQLException e) {
e.printStackTrace();
}
}
// 根据Id查询goods表,并封装成bean
public Goods getGoodsInfo(int gId)throws UnsupportedEncodingException{
Goods goodinfo = null;
String sql = "select * from goods where gId= " + gId;
try {
rs = stmt.executeQuery(sql);
while (rs.next()) {
byte[] b= rs.getBytes("goodsName");
String goodsName= new String(b,"utf-8");
goodinfo = new Goods(rs.getInt(1), rs.getString("goodsCode"),goodsName, rs.getFloat("goodsPrice"));
}
} catch (SQLException e) {
e.printStackTrace();
}
return goodinfo;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -