goodsinfoimplement.java

来自「JavaBean+Jsp 开发的《手机商城系统》」· Java 代码 · 共 44 行

JAVA
44
字号
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 + =
减小字号Ctrl + -
显示快捷键?