⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 goodsdao.java

📁 超市图书管理系统 可以在线购买和查阅书籍
💻 JAVA
字号:
package com.aowin.dao;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Set;


import com.aowin.model.Goods;
import com.aowin.util.DBConnection;

public class GoodsDao {

	DBConnection conn = new DBConnection();
	
	
	public int getPriceByName(String goodsName)
	{
		  int price =0 ;
		  String sql ="select * from tgoods where TG_name='" + goodsName +  "'" ;
		  System.out.println(sql);
		  ResultSet rs = conn.executeQuery(sql);
		  try {
			if(rs.next())
			  {
				  price= rs.getInt("TG_price");
			  }
		} catch (SQLException e) {
			e.printStackTrace();
		}finally
		{
			conn.close();
		
		}
		
		return price ;
	}
	  public ArrayList getAllGoods()
	  {
		  
		
		  ArrayList al = new ArrayList();
		
		  String sql ="select * from tgoods" ;
		  ResultSet rs = conn.executeQuery(sql);
		  try {
			while(rs.next())
			  {
				  Goods goods =new Goods();
				  goods.setName(rs.getString("TG_name"));
				  goods.setPrice(rs.getInt("TG_price"));
				  al.add(goods);
			  }
		} catch (SQLException e) {
			
			e.printStackTrace();
		}finally
		{
			conn.close();
		
		}
		
		return al ;
	  }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -