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

📄 cpumodify.java

📁 java编写的电子商务网站源码,做的一个电脑直销网站,后台数据库使用的是MS SQL2000 Server,数据流的流向主要有两个方向
💻 JAVA
字号:
package beans;

import java.sql.*;
import javax.servlet.jsp.*;
import java.util.*;
import java.io.UnsupportedEncodingException;
import common.Log;

public class CpuModify {
	private String driver = "com.microsoft.jdbc.sqlserver.SQLServerDriver";
	private String url = "jdbc:microsoft:sqlserver://localhost:1433";
	private String user = "nick";
	private String passwd = "123";
	private Connection c = null;
	private PreparedStatement ps = null;
	private ResultSet rs = null;
	private String submit = null;
	private int id = 0;
	private int type = 1;
	private String manufactor = null;
	private String name = null;
	private int speed = 0;
	private int price = 0;
	private int trend = 0;
	private int count = 0;

	public CpuModify() throws JspException {
		try {
			Class.forName(driver);
		}
		catch (ClassNotFoundException cnfe) {
			throw new JspException(cnfe);
		}
	}
	/*	获取和设置要执行的功能	*/
	public String getSubmit() {
		return this.submit;
	}
	public void setSubmit(String submit) {
		this.submit = encoding(submit);
	}
	/*	获取和设置id	*/
	public int getId() {
		return this.id;
	}
	public void setId(int id) {
		this.id = id;
	}
	/*	获取和设置CPU类型	*/
	public int getType() {
		return this.type;
	}
	public void setType(int type) {
		this.type = type;
	}
	/*	获取和设置CPU生产商的名字	*/
	public String getManufactor() {
		return this.manufactor;
	}
	public void setManufactor(String manufactor) {
		this.manufactor = encoding(manufactor);
	}
	/*	获取和设置CPU名称	*/
	public String getName() {
		return this.name;
	}
	public void setName(String name) {
		this.name = encoding(name);
	}
	/*	获取和设置CPU主频	*/
	public int getSpeed() {
		return this.speed;
	}
	public void setSpeed(int speed) {
		this.speed = speed;
	}
	/*	获取和设置CPU价格	*/
	public int getPrice() {
		return this.price;
	}
	public void setPrice(int price) {
		this.price = price;
	}
	/*	获取和设置CPU涨跌趋势	*/
	public int getTrend() {
		return this.trend;
	}
	public void setTrend(int trend) {
		this.trend = trend;
	}
	public int getCount(){
		return this.count;
	}
	public void setCount(int count){
		this.count = count;
	}
	
	/*	查询操作	*/
	public synchronized void query() {
		try {
			c = DriverManager.getConnection(url, user, passwd);
			ps =
				c.prepareStatement(
					"select * from cpu",
					ResultSet.TYPE_SCROLL_INSENSITIVE,
					ResultSet.CONCUR_UPDATABLE);
			rs = ps.executeQuery();
		}
		catch (SQLException sqle) {
			sqle.printStackTrace(System.out);
		}
	}

	/*	插入操作	*/
	public synchronized void insert() {
		try {
			c = DriverManager.getConnection(url, user, passwd);
			ps =
				c.prepareStatement(
					"insert into cpu (id,type,manufactor,name,speed,price,trend) values(?,?,?,?,?,?,?) ");
			ps.setInt(1,count+1);			
			ps.setInt(2, type);
			ps.setString(3, manufactor);
			ps.setString(4, name);
			ps.setInt(5, speed);
			ps.setInt(6, price);
			ps.setInt(7, trend);
			ps.executeUpdate();
			Log.writeLog(
				Calendar.getInstance().getTime().toString(),
				ps.toString());
		}
		catch (SQLException sqle) {
			sqle.printStackTrace(System.out);
		}
	}

	/*	删除操作	*/
	public synchronized void delete() {
		try {
			c = DriverManager.getConnection(url, user, passwd);
			ps = c.prepareStatement("delete from cpu where id = ?");
			ps.setInt(1, id);
			ps.executeUpdate();
			Log.writeLog(
				Calendar.getInstance().getTime().toString(),
				ps.toString());
		}
		catch (SQLException sqle) {
			sqle.printStackTrace(System.out);
		}
	}

	/*	修改操作	*/
	public synchronized void update() {
		try {
			c = DriverManager.getConnection(url, user, passwd);
			ps =
				c.prepareStatement(
					"update cpu set type = ?,manufactor = ?,name = ?,speed = ?,price = ?,trend = ? where id = ?");
			ps.setInt(1, type);
			ps.setString(2, manufactor);
			ps.setString(3, name);
			ps.setInt(4, speed);
			ps.setInt(5, price);
			ps.setInt(6, trend);
			ps.setInt(7, id);
			ps.executeUpdate();
			Log.writeLog(
				Calendar.getInstance().getTime().toString(),
				ps.toString());
		}
		catch (SQLException sqle) {
			sqle.printStackTrace(System.out);
		}
	}

	public void setRow(int row) {
		try {
			rs.absolute(row);
			ResultSetMetaData rsmd = rs.getMetaData();
			int column = rsmd.getColumnCount();
			for (int i = 0; i <= column; i++) {
				System.out.print(rs.getString(i) + "\t");
			}
			System.out.println();
		}
		catch (SQLException sqle) {
			sqle.printStackTrace(System.out);
		}
	}

	public void Operate() {
		if (getSubmit() != null) {
			if (getSubmit().equals("增加")) {			
				insert();
			}
			else if (getSubmit().equals("删除")) {			
				delete();
			}
			else if (getSubmit().equals("修改")) {			
				update();
			}
		}
	}

	private String encoding(String input) {
		try {
			return new String(input.getBytes("ISO-8859-1"), "GB2312");
		}
		catch (UnsupportedEncodingException uee) {
			return input;
		}
	}
}

⌨️ 快捷键说明

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