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

📄 informationsearch.java

📁 这是一个简单的图书管理系统,适用于教学中演示,讲解java高级编程语言
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
	    		
	    		  String str1,str11; 
	    		  do{str[i]=text[i].getText();
	    				if(str[i].equals(""))
	    					isNotNull[i]=false;
	    				else
	    					isNotNull[i]=true;
	    				i++;
	    			} while(i<4);
		    		 if(isNotNull[0])
		    		 { str1=str4[comboBox[0].getSelectedIndex()];
		    		 if(comboBox[1].getSelectedIndex()==2)
		    			 { if(comboBox[2].getSelectedIndex()==1)
		    				 { str3[0]=str1+" NOT LIKE '%"+str[0]+"'"; }
		    				 else if(comboBox[2].getSelectedIndex()==2)
		    				 {str3[0]=str1+"  NOT LIKE '"+str[0]+"%'";}
		    				 else if(comboBox[2].getSelectedIndex()==3)
		    				 {str3[0]=str1+" NOT LIKE '"+str[0]+"'";}
		    				 else{str3[0]=str1+" NOT LIKE '%"+str[0]+"%'";}
		    				 }
		    		 else 
		    		       {
		    			// str11=str2[comboBox[1].getSelectedIndex()];
		    			 if(comboBox[2].getSelectedIndex()==1)
		    				 {str3[0]=str1+" LIKE '%"+str[0]+"'";}
		    				 else if(comboBox[2].getSelectedIndex()==2)
		    				 { str3[0]=str1+" LIKE '"+str[0]+"%'";}
		    				 else if(comboBox[2].getSelectedIndex()==3)
		    				 {str3[0]=str1+" LIKE '"+str[0]+"'";}
		    				 else{str3[0]=str1+" LIKE '%"+str[0]+"%'";}
		    			 }
		    			 }
		    		  else str3[0]="";
		    		 //System.out.println("1"+str3[0]);
		    	   if(isNotNull[1]){
		    			 str1=str4[comboBox[3].getSelectedIndex()];
		    			 if(comboBox[1].getSelectedIndex()==2)
		    			 {if(comboBox[2].getSelectedIndex()==1)
		    				 {str3[1]="AND "+str1+" NOT LIKE '%"+str[1]+"'";}
		    				 else if(comboBox[2].getSelectedIndex()==2)
		    				 {str3[1]="AND "+str1+"  NOT LIKE '"+str[1]+"%'"; }
		    				 else if(comboBox[2].getSelectedIndex()==3)
		    				 {str3[1]="AND "+str1+"NOT LIKE '"+str[1]+"'";}
		    				 else{str3[1]="AND "+str1+" NOT LIKE '%"+str[1]+"%'";}
		    			 }else{str11=str2[comboBox[1].getSelectedIndex()];
		    				 if(comboBox[2].getSelectedIndex()==1)
		    				 {str3[1]=str11+" "+str1+" LIKE '%"+str[1]+"'";}
		    				 else if(comboBox[2].getSelectedIndex()==2)
		    				 {str3[1]=str11+" "+str1+" LIKE '"+str[1]+"%'";}
		    				 else if(comboBox[2].getSelectedIndex()==3)
		    				 {str3[1]=str11+" "+str1+" LIKE '"+str[1]+"'";}
		    				 else{str3[1]=str11+" "+str1+" LIKE'%"+str[1]+"%'";}
		    			 }} 
		    		 else str3[1]="";//System.out.println("2"+str3[1]);
		    	   if(isNotNull[2])
		    		 {str1=str4[comboBox[6].getSelectedIndex()];
		    		if(comboBox[4].getSelectedIndex()==2)
		    			 {if(comboBox[5].getSelectedIndex()==1)
		    				 {str3[2]="AND "+str1+" NOT LIKE '%"+str[2]+"'"; }
		    				 else if(comboBox[5].getSelectedIndex()==2)
		    				 {str3[2]="AND "+str1+"  NOT LIKE '"+str[2]+"%'";}
		    				 else if(comboBox[5].getSelectedIndex()==3)
		    				 {str3[1]="AND "+str1+"NOT LIKE '"+str[2]+"'";}
		    				 else {str3[2]="AND "+str1+" NOT LIKE '%"+str[2]+"%'";}
		    			 }else {str11=str2[comboBox[4].getSelectedIndex()];
		    				 if(comboBox[5].getSelectedIndex()==1)
		    				 { str3[2]=str11+" "+str1+" LIKE '%"+str[2]+"'";}
		    				 else if(comboBox[5].getSelectedIndex()==2)
		    				 {str3[2]=str11+" "+str1+" LIKE '"+str[2]+"%'";}
		    				 else if(comboBox[5].getSelectedIndex()==3)
		    				 {str3[2]=str11+" "+str1+" LIKE '"+str[2]+"'"; }
		    				 else {str3[2]=str11+" "+str1+" LIKE'%"+str[2]+"%'";}
		    			 } } 
		    		 else  str3[2]="";
		    	  // System.out.println("3"+str3[2]);
		    	   if(isNotNull[3]){
		    			 str1=str4[comboBox[9].getSelectedIndex()];
		    			 if(comboBox[7].getSelectedIndex()==2)
		    			 {if(comboBox[8].getSelectedIndex()==1)
		    				 {str3[3]="AND "+str1+" NOT LIKE '%"+str[3]+"'";}
		    				 else if(comboBox[8].getSelectedIndex()==2)
		    				 {str3[3]="AND "+str1+"  NOT LIKE '"+str[3]+"%'";}
		    				 else if(comboBox[8].getSelectedIndex()==3)
		    				 {str3[3]="AND "+str1+"NOT LIKE '"+str[3]+"'";}
		    				 else{str3[3]="AND "+str1+" NOT LIKE '%"+str[3]+"%'";}
		    			 }else{str11=str2[comboBox[7].getSelectedIndex()];
		    				 if(comboBox[8].getSelectedIndex()==1)
		    				 {str3[3]=str11+" "+str1+" LIKE '%"+str[3]+"'";}
		    				 else if(comboBox[8].getSelectedIndex()==2)
		    				 {str3[3]=str11+" "+str1+" LIKE '"+str[3]+"%'"; }
		    				 else if(comboBox[8].getSelectedIndex()==3)
		    				 {str3[3]=str11+" "+str1+" LIKE '"+str[3]+"'";}
		    				 else{str3[3]=str11+" "+str1+" LIKE'%"+str[3]+"%'";}
		    			 }} 
		    		 else str3[3]="";
		    	 //  System.out.println("4"+str3[3]);
		    	   Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); 
					Connection con = DriverManager.getConnection(dbURL, user,
							password); 
		    	    String sqlStr="SELECT  * FROM Book where "+str3[0]+str3[1]+str3[2]+str3[3];
		    	  //  System.out.println("4"+sqlStr);
		    	   
		    	    Statement st = con.createStatement();
		    	    ResultSet rs = st.executeQuery(sqlStr);
		    	    int k=0;
		    	    while (rs.next()) 
			         { 
		    	    	isExit=true;			
						for (int m = 0; m < columnNames.length; m++)
							rowData[k][m] = rs.getString(columnNames[m]); 
							k++;
				}
		    	    
			
		    	    if(!isExit)
		    	    	JOptionPane .showMessageDialog(null,"您所查找的书没有查到!" ); 
				con.close(); 
			
			} catch (Exception ex) {
				JOptionPane.showMessageDialog(InformationSearch.this,
				"数据库连接错误!\n"+ex);	
				ex.printStackTrace(); 
			}

			

			getContentPane().add(new JScrollPane(table), BorderLayout.CENTER); 

			Dimension screen = getToolkit().getScreenSize();

		setSize(screen.width - 90, 200);
			setLocation((screen.width - getSize().width) / 2,
					(screen.height - getSize().height) / 2);
			setVisible(true); 
			setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
			addWindowListener(new WindowAdapter() {
				public void windowClosing(WindowEvent e) {
					dispose();
				}
			});
		}
			}
			}
	private class ReaderSearchButton {
		private String dbURL = "jdbc:odbc:Student2007"; // 数据库标识名

		private String user = "devon"; // 数据库用户

		private String password = "book"; // 数据库用户密码
		//private JTable table;

		public ReaderSearchButton() {
			try {
				Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
				Connection con = DriverManager.getConnection(dbURL, user,
						password);
				String[] columnNames = { "类别", "查询内容"}; 
				String[] rowNames={"读者编号","读者识别号","读者姓名","读者权限","读者联系方法",
						"读者电子邮件","读者电话号码","借书数目"};
				Object[][] rowData = new Object[rowNames.length][columnNames.length]; 
				
				
				Statement st = con.createStatement();
				ResultSet rs = st.executeQuery("SELECT * FROM Reader WHERE 读者识别号 = '"
						+ comboBox[12].getSelectedItem() + "' ");

				if (rs.next()) {
				/*	for(int i=0;i<rowData.length;i++){
						for(int j=0;i<rowData[i].length;i++){
							if(i==0)
							rowData[i][j]=rowNames[j];
							else rowData[i][j]=rs.getString(j+1);
						}
					}
					//table.addColumn(arg0);
					//table = new JTable(rowData, columnNames); 
					//table.setEnabled(false);
				/*	JPanel jpanel=new JPanel();
					jpanel.add(new JScrollPane(table));
					txt.add(jPanel);*/
				
					txt.setText("读者编号: " + rs.getInt(1) + "\n" + "读者识别号: "
							+ rs.getString(2) + "\n" + "读者姓名:"
							+ rs.getString(3) + "\n" + "读者权限: "
							+ rs.getString(4) + "\n" + "读者联系方法: "
							+ rs.getString(5) + "\n" + "读者电子邮件: "
							+ rs.getString(6) + "\n" + "读者电话号码: "
							+ rs.getString(7) + "\n" + "借书数目: "
							+ rs.getInt(8));

				} else {
					
					
					for(int i=0;i<rowData.length;i++){
						for(int j=0;i<rowData[i].length;i++){
							if(i==0)
							rowData[i][j]=rowNames[j];
							else rowData[i][j]="无";
						}
					}
				//	table = new JTable(rowData, columnNames); 
				//table.setEnabled(false);
				//	txt.add(new JScrollPane(table)); 
					
					
					txt.setText("查无此读者!\n"+"读者编号: 无" + "\n" + "读者识别号: 无"
							 + "\n" + "读者姓名:无"
							 + "\n" + "读者权限: 无"
							 + "\n" + "读者联系方法: 无"
							 + "\n" + "读者电子邮件:无 "
							 + "\n" + "读者电话号码: 无"
							 + "\n" + "借书数目: 无"
							);
					 JOptionPane.showMessageDialog(InformationSearch.this,
								"没有找到您所找的读者,\n请确认您的输入是否正确!");

				}

				con.close();
			} catch (Exception ex) {
				JOptionPane.showMessageDialog(InformationSearch.this,
				"数据库连接错误!\n"+ex);	
				ex.printStackTrace();
			}
		}

	}

}

⌨️ 快捷键说明

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