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

📄 list.java

📁 用Java开发的购物车程序!
💻 JAVA
字号:
package mypackage;

import java.sql.*;
import java.io.*;
import java.util.*;

public class List
{
	private Connection conn=null;
	private Statement stmt=null;
	private ResultSet rs=null;
	private static String constr="jdbc:oracle:thin:@localhost:1521:oracle";
	private int cid;
	private String cdesc="";
	
	public List()
	{
		try
		{
			Class.forName("oracle.jdbc.driver.OracleDriver");
		}
		catch(Exception e)
		{
			e.printStackTrace();
		}
		
	}
	
	public void setCid(int cid)
	{
		this.cid=cid;
	}
	
	public void setCdesc(String cdesc)
	{
		this.cdesc=cdesc;
	}
	
	public int getCid()
	{
		return this.cid;
	}
	
	public String getCedsc()
	{
		return this.cdesc;
	}
	
	public String[] getCate()throws Exception 
	{
		Vector v=new Vector();
		try
		{
			conn=DriverManager.getConnection(constr,"scott","tiger");
			stmt=conn.createStatement();
			rs=stmt.executeQuery("select cdesc from category");
			while(rs.next())
			{
				String s=rs.getString(1);
				v.add(s);
			}
		}
		catch(Exception e)
		{
			e.printStackTrace();
		}
		conn.close();
		String[] str=new String[v.size()];
		for(int i=0;i<v.size();i++)
		str[i]=(String)v.elementAt(i);
		return str;
	}
	
	public int getCidByCate(String cate)throws Exception
	{
		int s=0;
		try
		{
			conn=DriverManager.getConnection(constr,"scott","tiger");
			stmt=conn.createStatement();
			rs=stmt.executeQuery("select cid from category where cdesc='"+cate+"'");
			while(rs.next())
			{
				s=rs.getInt(1);
			}
		}
		catch(Exception e)
		{
			e.printStackTrace();
		}
		conn.close();
		return s;
		
	}
	
	public Product[] getProList(int cid)throws Exception
	{
		Vector v=new Vector();
		Product pd[]={};
		try
		{
			conn=DriverManager.getConnection(constr,"scott","tiger");
			stmt=conn.createStatement();
			rs=stmt.executeQuery("select * from products where cat="+cid);
			
			while(rs.next())
			{
				Product p=new Product();
				p.setPname(rs.getString("pname"));
				p.setPid(rs.getInt("pid"));
				v.add(p);
			}
			pd=new Product[v.size()];
			for(int i=0;i<v.size();i++)
			pd[i]=(Product)v.elementAt(i);
		}
		catch(Exception e)
		{
			e.printStackTrace();
		}
		conn.close();
		return pd;
		
	}
	
	public Product getProduct(int pid)throws Exception
	{
		Product p=new Product();
		try
		{
			conn=DriverManager.getConnection(constr,"scott","tiger");
			stmt=conn.createStatement();
			rs=stmt.executeQuery("select * from products where pid="+pid);
			
			rs.next();
			
				p.setPname(rs.getString("pname"));
				p.setPid(rs.getInt("pid"));
				p.setPrice(rs.getFloat("price"));
		}
		catch(Exception e)
		{
			e.printStackTrace();
		}
		conn.close();
		return p;
		
	}	
	public static void main(String[] args)throws Exception
	{
		List li=new List();
		Product j=li.getProduct(101);
		System.out.println(j.getPrice());
	}
}

⌨️ 快捷键说明

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