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

📄 harddiskmodify.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 HarddiskModify {
	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 String manufactor = null;
	private String name = null;
	private int revolution = 0;
	private int volumn = 0;
	private int price = 0;
	private int trend = 0;
	private int count = 0;

	public HarddiskModify() 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;
	}
	/*	获取和设置硬盘生产商的名字	*/
	public String getManufactor() {
		return this.manufactor;
	}
	public void setManufactor(String manufactor) {
		this.manufactor = encoding(manufactor);
	}
	/*	获取和设置硬盘名称	*/
	public String getName() {
		return this.name;
	}
	public void setName(String name) {
		this.name = encoding(name);
	}
	/*	获取和设置硬盘转数	*/
	public int getRevolution() {
		return this.revolution;
	}
	public void setRevolution(int revolution) {
		this.revolution = revolution;
	}
	/*	获取和设置硬盘的容量	*/
	public int getVolumn() {
		return this.volumn;
	}
	public void setVolumn(int volumn) {
		this.volumn = volumn;
	}
	/*	获取和设置硬盘价格	*/
	public int getPrice() {
		return this.price;
	}
	public void setPrice(int price) {
		this.price = price;
	}
	/*	获取和设置硬盘涨跌趋势	*/
	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 harddisk",
					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 harddisk (id,manufactor,name,revolution,volumn,price,trend) values(?,?,?,?,?,?,?)");
			ps.setInt(1, count + 1);
			ps.setString(2, manufactor);
			ps.setString(3, name);
			ps.setInt(4, revolution);
			ps.setInt(5, volumn);
			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 harddisk 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 harddisk set manufactor = ?,name = ?,revolution = ?,volumn = ?,price = ?,trend = ? where id = ?");
			ps.setString(1, manufactor);
			ps.setString(2, name);
			ps.setInt(3, revolution);
			ps.setInt(4, volumn);
			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 + -