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

📄 members.java

📁 这是用elipes平台开发的java编程实例,数据库用access .若想用elipes软件加以开发只要连接该数据库即可.数据库连接步骤如下:"开始"-"设置"-"控制面板"-"管理工具"-"数据源"
💻 JAVA
字号:
package lib;
import java.sql.*;

public class Members {
	/***************************************************************************
	 ***      declaration of the private variables used in the program       ***
	 ***************************************************************************/

	private Connection connection = null;
	private Statement statement = null;
	private ResultSet resultSet = null;

	private int memberID;
	private int ID;
	private String password;
	private String name;
	private String email;
	private String major;
	private int numberOfBooks;
	private float money;
	private Date expired;
	private String URL = "jdbc:odbc:JLibrary";
	private boolean type = true;
	public Members() {
	}
	public void setType(boolean type){
	    this.type = type;
	}
	public boolean getType()
	{
	    return this.type;
	}
	
	public int getMemberID() {
		return memberID;
	}

	public int getID() {
		return ID;
	}

	public String getPassword() {
		return password;
	}

	public String getName() {
		return name;
	}

	public String getEmail() {
		return email;
	}

	public String getMajor() {
		return major;
	}

	public int getNumberOfBooks() {
		return numberOfBooks;
	}

	public float getMoney() {
		return money;
	}

	public Date getExpired() {
		return expired;
	}

	public void connection(String Query) {
		try {
			Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
		}
		catch (ClassNotFoundException cnfe) {
			System.out.println("Members.java\n" + cnfe.toString());
		}
		catch (Exception e) {
			System.out.println("Members.java\n" + e.toString());
		}
		/***************************************************************
		 * for making the connection,creating the statement and update *
		 * the table in the database. After that,closing the statmenet *
		 * and connection. There is catch block SQLException for error *
		 ***************************************************************/
		try {
			connection = DriverManager.getConnection(URL);
			statement = connection.createStatement();
			resultSet = statement.executeQuery(Query);
			while (resultSet.next()) {
			    ID = resultSet.getInt("ID");
			    password = resultSet.getString("Password");
			    name = resultSet.getString("NAME");
			    if(type){
			    memberID = resultSet.getInt("MemberID");
				email = resultSet.getString("EMAIL");
				major = resultSet.getString("Major");
				numberOfBooks = resultSet.getInt("NumberOfBooks");
				money = resultSet.getFloat("Money");
				expired = resultSet.getDate("Expired");}
			}
			resultSet.close();
			statement.close();
			connection.close();
		}
		catch (SQLException SQLe) {
			System.out.println("Members.java\n" + SQLe.toString());
		}
	}

	public void update(String Query) {
		try {
			Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
		}
		catch (ClassNotFoundException cnfe) {
			System.out.println("Members.java\n" + cnfe.toString());
		}
		catch (Exception e) {
			System.out.println("Members.java\n" + e.toString());
		}
		/***************************************************************
		 * for making the connection,creating the statement and update *
		 * the table in the database. After that,closing the statmenet *
		 * and connection. There is catch block SQLException for error *
		 ***************************************************************/
		try {
			connection = DriverManager.getConnection(URL);
			statement = connection.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_UPDATABLE);
			statement.executeUpdate(Query);
			statement.close();
			connection.close();
		}
		catch (SQLException SQLe) {
			System.out.println("Members.java\n" + SQLe.toString());
		}
	}
}

⌨️ 快捷键说明

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