calculatorimpl.java

来自「图书馆的图书管理系统! 图书查询」· Java 代码 · 共 1,028 行 · 第 1/2 页

JAVA
1,028
字号
						}
						break;
					} else {
						u = 1;
						break;
					}
				}
			}
			if (u == 1) {
				ResultSet re1 = s1.executeQuery(str);
				re1.next();
				for (int i = 0; i < 8; i++) {
					book[i] = (String) re1.getString(i + 1);
				}
				u = 0;

			}

			con.close();
			con1.close();
			s.close();
			s1.close();
		}
		if (a == 1) {
			String driver = "sun.jdbc.odbc.JdbcOdbcDriver";
			try {
				Class.forName(driver);
			} catch (ClassNotFoundException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			String url = "jdbc:odbc:lib";
			Connection con = DriverManager.getConnection(url);
			Connection con1 = DriverManager.getConnection(url);
			Statement s = con.createStatement();
			Statement s1 = con1.createStatement();
			String str = "select* from book";
			ResultSet re = s.executeQuery(str);

			String ID = "";
			String ID1 = "";
			String b1 = Integer.toString(b);
			int o = 0;
			while (re.next()) {
				ID = re.getString(1);
				if (ID.equals(b1)) {
					book[0] = ID1;
					break;
				}
				ID1 = ID;
				o++;
			}
			ResultSet re1 = s1.executeQuery(str);
			if (ID1.equals("")) {
				while (re.next()) {
					// ID1 = re.getString(1);
					// book[0] = ID1;
					for (int i = 0; i < 8; i++) {

						book[i] = re.getString(i + 1);

					}

				}

			} else {
				book[0] = ID1;
				for (int i = 0; i < o; i++)
					re1.next();
				for (int i = 1; i < 8; i++) {

					book[i] = re1.getString(i + 1);

				}

			}

			con.close();
			s.close();
		}
		return book;
	}

	public boolean book(int a) throws java.rmi.RemoteException, SQLException {
		String driver = "sun.jdbc.odbc.JdbcOdbcDriver";
		try {
			Class.forName(driver);
		} 
		catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		boolean l = false;
		String url = "jdbc:odbc:lib";
		
		Connection con = DriverManager.getConnection(url);
		Statement s = con.createStatement();
		String str = "select* from book";
		ResultSet re = s.executeQuery(str);
		
		while (re.next()) {
			int ID = Integer.parseInt(re.getString(1));
			if (ID==a) {
				l = true;
				
				break;
			}
		}

		if (l == true) {

			s.executeUpdate("DELETE  FROM book WHERE bookID=" + a);


			
		} 

		con.close();
		s.close();
		return l;
	}

	public boolean reader(int a, String b, int c, String d, double e, String f,
			int g) throws java.rmi.RemoteException, SQLException {
		boolean rt = true;
		if (g == 0) {
			String driver = "sun.jdbc.odbc.JdbcOdbcDriver";
			try {
				Class.forName(driver);
			} catch (Exception x) {
				System.out.println(x.toString());
			}
			String url = "jdbc:odbc:lib";
			Connection con = DriverManager.getConnection(url);
			Statement s = con.createStatement();
			String str = "select * from reader";
			ResultSet re = s.executeQuery(str);

			while (re.next()) {
				int ID = Integer.parseInt(re.getString(1));
				if (ID == a) {
					rt = false;
					break;
				}

			}
			if (rt == true) {
				// System.out.print(f);
				String str1 = "INSERT INTO reader VALUES(" + a + ",'" + b
						+ "'," + c + ",'" + d + "'," + e + ",'" + f + "')";
				s.executeUpdate(str1);
			}
			// System.out.print(f);
			con.close();
			s.close();
		}
		if (g == 1) {
			String driver = "sun.jdbc.odbc.JdbcOdbcDriver";
			try {
				Class.forName(driver);
			} catch (ClassNotFoundException e1) {
				// TODO Auto-generated catch block
				e1.printStackTrace();
			}

			String url = "jdbc:odbc:lib";
			Connection con = DriverManager.getConnection(url);
			Statement s = con.createStatement();
			String str = "select * from reader";
			ResultSet re = s.executeQuery(str);
			rt = false;
			System.out.print(rt);
			while (re.next()) {
				int ID = Integer.parseInt(re.getString(1));
				if (ID == a) {
					rt = true;
					break;
				}
			}
			System.out.print(rt);
			System.out.print(c);
			String c1 = Integer.toString(c);
			String e1 = Double.toString(e);
			System.out.print(c1);
			if (rt == true) {
				s.execute("update reader set Name='" + b + "' where readerID="
						+ a);
				s.execute("update reader set ReaderLevel='" + c1
						+ "' where readerID=" + a);
				s.execute("update reader set TelephoneNumber='" + e1
						+ "' where readerID=" + a + "");
				s.execute("update reader set Email='" + f + "' where readerID="
						+ a + "");
				s.execute("update reader set Address='" + d
						+ "' where readerID=" + a + "");
			}
			s.close();
			con.close();
		}

		return rt;

	}

	public String[] reader(int a, int b) throws java.rmi.RemoteException,
			SQLException {
		String[] book = new String[6];
		if (a == 0) {
			String driver = "sun.jdbc.odbc.JdbcOdbcDriver";
			try {
				Class.forName(driver);
			} catch (ClassNotFoundException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			int u = 0;
			String url = "jdbc:odbc:lib";
			Connection con = DriverManager.getConnection(url);
			Connection con1 = DriverManager.getConnection(url);
			Statement s = con.createStatement();
			Statement s1 = con1.createStatement();
			String str = "select* from reader";
			ResultSet re = s.executeQuery(str);
			while (re.next()) {
				int ID = Integer.parseInt(re.getString(1));
				if (ID == b) {
					if (re.next()) {
						book[0] = Integer.toString(ID + 1);
						for (int i = 1; i < 6; i++) {
							book[i] = (String) re.getString(i + 1);
						}
						break;
					} else {
						u = 1;
						break;
					}
				}
			}
			if (u == 1) {
				ResultSet re1 = s1.executeQuery(str);
				re1.next();
				for (int i = 0; i < 6; i++) {
					book[i] = (String) re1.getString(i + 1);
				}
				u = 0;

			}

			con.close();
			con1.close();
			s.close();
			s1.close();
		}
		if (a == 1) {
			String driver = "sun.jdbc.odbc.JdbcOdbcDriver";
			try {
				Class.forName(driver);
			} catch (ClassNotFoundException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			String url = "jdbc:odbc:lib";
			Connection con = DriverManager.getConnection(url);
			Connection con1 = DriverManager.getConnection(url);
			Statement s = con.createStatement();
			Statement s1 = con1.createStatement();
			String str = "select* from reader";
			ResultSet re = s.executeQuery(str);

			String ID = "";
			String ID1 = "";
			String b1 = Integer.toString(b);
			int o = 0;
			while (re.next()) {
				ID = re.getString(1);
				if (ID.equals(b1)) {
					book[0] = ID1;
					break;
				}
				ID1 = ID;
				o++;
			}
			ResultSet re1 = s1.executeQuery(str);
			if (ID1.equals("")) {
				while (re.next()) {
					// ID1 = re.getString(1);
					// book[0] = ID1;
					for (int i = 0; i < 6; i++) {

						book[i] = re.getString(i + 1);

					}

				}

			} else {
				book[0] = ID1;
				for (int i = 0; i < o; i++)
					re1.next();
				for (int i = 1; i < 6; i++) {

					book[i] = re1.getString(i + 1);

				}

			}

			con.close();
			s.close();
		}
		return book;
	}

	public boolean reader(int a) throws java.rmi.RemoteException, SQLException {
		String driver = "sun.jdbc.odbc.JdbcOdbcDriver";
		try {
			Class.forName(driver);
		} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		boolean l = false;
		String url = "jdbc:odbc:lib";
		Connection con = DriverManager.getConnection(url);
		Statement s = con.createStatement();
		String str = "select* from reader";
		ResultSet re = s.executeQuery(str);
		while (re.next()) {
			int ID = Integer.parseInt(re.getString(1));
			if (ID==a) {
				l = true;
				
				break;
			}
		}
		if (l == true) {
			s.executeUpdate("DELETE  FROM reader WHERE ReaderID=" + a);
//			JOptionPane.showMessageDialog(null, "编号为" + a + "的读者"
//					+ re.getString(2) + "已从数据库中删除");
		} else
//			JOptionPane.showMessageDialog(null, "对不起,数据库无该读者记录,请确认您的输入");
		con.close();
		s.close();
		return l;
	}

	public String[] tj() throws java.rmi.RemoteException, SQLException {
		String driver = "sun.jdbc.odbc.JdbcOdbcDriver";
		String[] tongji = new String[3];
		try {
			Class.forName(driver);
		} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		int a = 0, b = 0, c = 0;
		String url = "jdbc:odbc:lib";
		Connection con = DriverManager.getConnection(url);
		Statement s = con.createStatement();
		String str = "select* from book";
		ResultSet re = s.executeQuery(str);
		while (re.next()) {
			a++;
		}
		String str1 = "select* from reader";
		ResultSet re1 = s.executeQuery(str1);
		while (re1.next()) {
			b++;
		}

		String str2 = "select* from book";
		ResultSet re2 = s.executeQuery(str2);
		while (re2.next()) {
			String z = re2.getString(8);
			if (z.equals("在馆"))
				c++;
		}
		tongji[0] = Integer.toString(a);
		tongji[1] = Integer.toString(b);
		tongji[2] = Integer.toString(c);

		con.close();
		s.close();
		return tongji;
	}

	public boolean config(int a, int b,int c) throws java.rmi.RemoteException,
			SQLException {

		String  driver="sun.jdbc.odbc.JdbcOdbcDriver";  			
		try {
			Class.forName(driver);
		} catch (ClassNotFoundException e) {
			// TODO 自动生成 catch 块
			e.printStackTrace();
		} 
		String  url="jdbc:odbc:lib";
		Connection  con=DriverManager.getConnection(url);
		 Statement s = con.createStatement(); 
		  	
		s. execute("update configuration set MaxBLNum="+b+" where ID="+a);
		s. execute("update configuration set MaxBLDays="+c+" where ID="+a);
		 s.close();
			con.close();
		return true;
	}

	public File[] data() throws java.rmi.RemoteException,
			SQLException {
		File[] roots = File.listRoots();
		return roots;
	}

	public File[] data1() throws java.rmi.RemoteException, SQLException {
		File[] roots = File.listRoots();
		return roots;
	}

	public int passwd(int a, String b, String c)
			throws java.rmi.RemoteException, SQLException {
		int p = 2;
		String driver = "sun.jdbc.odbc.JdbcOdbcDriver";
		try {
			Class.forName(driver);
		} catch (Exception e) {
			System.out.println(e.toString());
		}
		String url = "jdbc:odbc:lib";
		Connection con = DriverManager.getConnection(url);
		Statement s = con.createStatement();
		String s_sql = "select * from administer ";
		ResultSet love = s.executeQuery(s_sql);
		// int i = 0;
		int o = b.length();
		double u = 1;
		char[] ii = new char[o];
		for (int t = 0; t < o; t++) {
			ii[t] = b.charAt(t);
			u = u * (double) ii[t];
		}
		String gyl = "";
		gyl = Long.toString((long) (u * Math.sqrt(519) * 377));
		int o1 = c.length();
		double u1 = 1;
		char[] ii1 = new char[o1];
		for (int t = 0; t < o1; t++) {
			ii1[t] = c.charAt(t);
			u1 = u1 * (double) ii1[t];
		}
		String gyl1 = "";
		gyl1 = Long.toString((long) (u1 * Math.sqrt(519) * 377));
		while (love.next()) {
			int ID = Integer.parseInt(love.getString(2));
			String 密码 = love.getString(3);
			if (ID == a) {
				if (gyl.equals(密码)) {
					p = 0;
					break;
				} else {
					// 输入密码错误
					p = 1;
					break;
				}
			} else {

				// 输入用户名或密码错误
				p = 2;
			}
		}
		String g=Integer.toString(a);
		if(p==0)
		{
			s.execute("update administer set Password ='"+gyl1+"' where Account1='" + g+"'");
		}
		con.close();
		s.close();

		return p;
	}
	
	public void write(String a) throws java.rmi.RemoteException, FileNotFoundException,IOException
	{

	       int   len   =   0;   
	        byte[]   buf   =   new   byte[1024];   
	        FileInputStream fis;
				fis = new   FileInputStream(a);
			  
	        FileOutputStream   fos   =   new   FileOutputStream("d:/LIB.mdb");   
	        while   ((len=fis.read(buf))!=-1)   {   
	            fos.write(buf,0,len);   
	        }

	        fis.close();   
	        fos.close(); 
	}
	
	public void write(String a,String b) throws java.rmi.RemoteException, FileNotFoundException,IOException
	{
	       int   len   =   0;   
	        byte[]   buf   =   new   byte[1024];   
	        FileInputStream fis;
				fis = new   FileInputStream("d:/LIB.mdb");
			  
	        FileOutputStream   fos   =   new   FileOutputStream(a+"/"+b);   
	        while   ((len=fis.read(buf))!=-1)   {   
	            fos.write(buf,0,len);   
	        }

	        fis.close();   
	        fos.close(); 
	}
}

⌨️ 快捷键说明

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