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

📄 projectlibrary.java

📁 a college inventory library system using javascript
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
				{jp.showMessageDialog(this,"Record Already Exists","EXCEPTION",jp.ERROR_MESSAGE);}
			}
       			if(source==update1)
			{
			            try
			               {		
					  Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
					    Connection c = DriverManager.getConnection("jdbc:odbc:Student");
					    Statement st = c.createStatement();
			
				PreparedStatement ps=c.prepareStatement ("Update Book set BookName=? , AuthorName=? , Price=? where BookCode="+bcodeTF.getText() ); 
					
					ps.setString(1,bookTF.getText());		
					ps.setString(2,authorTF.getText());
					ps.setInt(3,Integer.parseInt(priceTF.getText()));
					ps.executeUpdate();
				jp.showMessageDialog(this,"Record Updated Successfully","SUCCESS",jp.INFORMATION_MESSAGE);
				c.close();
				st.close();
			 }
			catch(ClassNotFoundException cnf)
			{System.out.println("Cnf Exception");}
			catch(SQLException sql)
			{jp.showMessageDialog(this,sql,"EXCEPTION",jp.ERROR_MESSAGE);}
		}    
		      	if(source==menuItemC)
			{	
				JFrame cd=new JFrame("CD's available in library");
				cd.setSize(510,540);	
				cd.getContentPane().setLayout(null);
				cd.getContentPane().setBackground(new Color(14,58,119));
				cd.getContentPane().setLayout(null);
				cd.setResizable(false);

				ImageIcon backg = new ImageIcon("CDLABEL.PNG");
				JLabel cdlogo = new JLabel(backg);
				cd.getContentPane().add(cdlogo);  
	
				cdcode = new JLabel("CD Code:"); cdcode.setForeground(Color.white);
				cdtitle = new JLabel("Title:"); cdtitle.setForeground(Color.white);
				cdisbn = new JLabel("ISBN NO:"); cdisbn .setForeground(Color.white);		
				cdedit = new JLabel("Edition:");	cdedit .setForeground(Color.white);
				cdpub = new JLabel("Publication:");cdpub .setForeground(Color.white);
				
				cdcodeTF = new JTextField();
				cdtitleTF = new JTextField();
				cdisbnTF = new JTextField();
				cdeditionTF = new JTextField();
				cdpubTF = new JTextField();
				
				cdsearch = new JButton("Search" , new ImageIcon("SEARCH.PNG"));
				cdsave = new JButton("Save", new ImageIcon("SAVE.PNG"));
				cddelete = new JButton("Delete", new ImageIcon("DELETE.PNG"));
				cdupdate = new JButton("Update", new ImageIcon("UPDATE.PNG"));
				cdexit = new JButton("Exit", new ImageIcon("EXIT.PNG"));
		
				cd.getContentPane().add(cdcode);
				cd.getContentPane().add(cdtitle);
				cd.getContentPane().add(cdisbn);
		 		cd.getContentPane().add(cdedit);
				cd.getContentPane().add(cdpub);
				
				cd.getContentPane().add(cdcodeTF);
				cd.getContentPane().add(cdtitleTF);
				cd.getContentPane().add(cdisbnTF);
				cd.getContentPane().add(cdeditionTF);
				cd.getContentPane().add(cdpubTF);
				
				cd.getContentPane().add(cdsearch);
				cd.getContentPane().add(cdsave);
				cd.getContentPane().add(cddelete);
				cd.getContentPane().add(cdupdate);
				cd.getContentPane().add(cdexit);
				
				cdlogo.setBounds(1,0,500,100);
				cdcode.setBounds(50,120,210,25);
				cdtitle.setBounds(50,160,210,25);
				cdisbn.setBounds(50,200,210,25);
				cdedit.setBounds(50,240,210,25);
				cdpub.setBounds(50,280,210,25);
				
				cdcodeTF.setBounds(150,120,210,25);
				cdtitleTF.setBounds(150,160,210,25);
				cdisbnTF.setBounds(150,200,210,25);
				cdeditionTF.setBounds(150,240,210,25);
				cdpubTF.setBounds(150,280,210,25);

				cdsearch.setBounds(0,420,98,25);
				cdsave.setBounds(100,420,98,25);
				cddelete.setBounds(200,420,98,25);
				cdupdate.setBounds(300,420,98,25);
				cdexit.setBounds(400,420,98,25);

				cdsearch.addActionListener(this);	
				cdsave.addActionListener(this);
				cddelete.addActionListener(this);
				cdexit.addActionListener(this);
				cdupdate.addActionListener(this);
				cd.setVisible(true);
 			}
			
			if(source==cdsearch)
			{
				try
				{

					Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
				       	Connection c = DriverManager.getConnection("jdbc:odbc:Student");
		                           		Statement st = c.createStatement();
					ResultSet rs = st.executeQuery("select * from CD  where CdCode="+cdcodeTF.getText());
				       while(rs.next())
		       			{	
						    cdtitleTF.setText(rs.getString("Title"));
						    cdisbnTF.setText(rs.getString("IsbnNO"));
					    	    cdeditionTF.setText(rs.getString("Edition"));
						    cdpubTF.setText(rs.getString("Publication"));
						       
		      			}
		    	    		c.close();
			        		st.close();
				  }
				  catch(ClassNotFoundException cnf)
				  {
					jp.showMessageDialog(this,cnf,"EXCEPTION",jp.ERROR_MESSAGE);
					System.out.println("Cnf Exception");
		 		   }
				catch(SQLException sql)
		  		{
				    	jp.showMessageDialog(this,sql,"EXCEPTION",jp.ERROR_MESSAGE);
				  }
		
	  		}
		
			if(source==cdsave)
			{
				try
				{
				Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
			    Connection c = DriverManager.getConnection("jdbc:odbc:Student");
			    Statement st = c.createStatement();
			    PreparedStatement ps  = c.prepareStatement("Insert into CD values(?,?,?,?,?)");
			
					ps.setString(1,cdcodeTF.getText());
					ps.setString(2,cdtitleTF.getText());
					ps.setString(3,cdisbnTF.getText());
					ps.setString(4,cdeditionTF.getText());
					ps.setString(5,cdpubTF.getText());
					ps.executeUpdate();
		jp.showMessageDialog(this,"Record Inserted Successfully","SUCCESS",jp.INFORMATION_MESSAGE);

				c.close();
				st.close();
			 }
			catch(ClassNotFoundException cnf)
			{
				System.out.println("Cnf Exception");
			}
			catch(SQLException sql)
			{
				jp.showMessageDialog(this,"Record Already Exists","EXCEPTION",jp.ERROR_MESSAGE);
			}
				
		}				
		
		if(source==cddelete)
		{
			try
			{
				Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
			    Connection c = DriverManager.getConnection("jdbc:odbc:Student");
			    Statement st = c.createStatement();
			    PreparedStatement ps=c.prepareStatement("Delete from CD where CdCode="+cdcodeTF.getText());
				ps.executeUpdate();
				jp.showMessageDialog(this,"Record Deleted Successfully","SUCCESS",jp.INFORMATION_MESSAGE);
				c.close();
				st.close();
			 }
			catch(ClassNotFoundException cnf)
			{
				System.out.println("Cnf Exception");
			}
			catch(SQLException sql)
			{
				jp.showMessageDialog(this,sql,"EXCEPTION",jp.ERROR_MESSAGE);

			}
			
		}
		if(source==cdupdate)
		{
			try
			      {
			
			  Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
			    Connection c = DriverManager.getConnection("jdbc:odbc:Student");
			    Statement st = c.createStatement();
			PreparedStatement ps=c.prepareStatement ("Update CD set Title=?, IsbnNO=?, Edition=?, Publication=?  where CdCode="+cdcodeTF.getText());
					
					ps.setString(1,cdtitleTF.getText());		
					ps.setString(2,cdisbnTF.getText());
					ps.setString(3,cdeditionTF.getText());
					ps.setString(4,cdpubTF.getText());
					ps.executeUpdate();
				jp.showMessageDialog(this,"Record Updated Successfully","SUCCESS",jp.INFORMATION_MESSAGE);
				c.close();
				st.close();
			 }
			catch(ClassNotFoundException cnf)
			{
				System.out.println("Cnf Exception");
			}
			catch(SQLException sql)
			{
				jp.showMessageDialog(this,sql,"EXCEPTION",jp.ERROR_MESSAGE);
			}
				
		}
		if(source==cdexit)
		{
			System.exit(0);
		}
		if(source==menuItemH)
		{
				JFrame help=new JFrame("Help ?");
				help.setSize(800,730);	
				help.getContentPane().setBackground(new Color(14,58,119));
				help.getContentPane().setLayout(null);
				help.setResizable(false);
				ImageIcon hl = new ImageIcon("helpLib.png");
				JLabel logoCD = new JLabel(hl);
				help.getContentPane().add(logoCD);  
				logoCD.setBounds(0,0,800,540);
				help.setVisible(true);
 		}
		if(source==searBook)
		{			
	                            try
			{

			Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
		       	Connection c = DriverManager.getConnection("jdbc:odbc:Student");
			       Statement st = c.createStatement();
			       ResultSet rs = st.executeQuery("select * from Book where BookCode="+bcodeTF.getText());
			       while(rs.next())
		       		{	
				    bookTF.setText(rs.getString("BookName"));	
			    	    authorTF.setText(rs.getString("AuthorName"));
				    priceTF.setText(rs.getString("Price"));
			    	    /*add.setText(rs.getString("Address"));
				    class1.setText(rs.getString("Class"));
				    progress.setText(rs.getString("Progress"));
				    phno.setText(rs.getString("PhoneNo"));
				    shift.setText(rs.getString("Shift"));
				    city.setText(rs.getString("City"));
				    padd.setText(rs.getString("Permenent_Address"));
				    eadd.setText(rs.getString("eaddress"));*/
				    
		      		}
		        	c.close();
		        	st.close();
		  }
		  catch(ClassNotFoundException cnf)
		  {
			jp.showMessageDialog(this,cnf,"EXCEPTION",jp.ERROR_MESSAGE);
			System.out.println("Cnf Exception");
		}
		catch(SQLException sql)
		  {
		    	jp.showMessageDialog(this,sql,"EXCEPTION",jp.ERROR_MESSAGE);
		  }
		
	  }
	
		if(str1.equals("Search"))
		{
    		try
		    {
		       Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
		       Connection c = DriverManager.getConnection("jdbc:odbc:Student");
		       Statement st = c.createStatement();
		       ResultSet rs = st.executeQuery("select * from Directory where Id="+id.getText());

		       while(rs.next())
		       {		   date.setText(rs.getString("DateToday"));	
			    	    id.setText(rs.getString("Id"));
				    name.setText(rs.getString("Name"));
			    	    add.setText(rs.getString("Address"));
				    class1.setText(rs.getString("Class"));
				    progress.setText(rs.getString("Progress"));
				    phno.setText(rs.getString("PhoneNo"));
				    shift.setText(rs.getString("Shift"));
				    city.setText(rs.getString("City"));
				    padd.setText(rs.getString("Permenent_Address"));
				    eadd.setText(rs.getString("eaddress"));
				    
		      }
		        	c.close();
		        	st.close();
		  }
		  catch(ClassNotFoundException cnf)
		  {
		    	jp.showMessageDialog(this,cnf,"EXCEPTION",jp.ERROR_MESSAGE);
		    	System.out.println("Cnf Exception");
		  }
		  catch(SQLException sql)
		  {
		    	jp.showMessageDialog(this,sql,"EXCEPTION",jp.ERROR_MESSAGE);
		  }
	  }

		if(str1.equals("Save"))
		{
			try
			{
				Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
			    Connection c = DriverManager.getConnection("jdbc:odbc:Student");
			    Statement st = c.createStatement();
			    PreparedStatement ps  = c.prepareStatement("Insert into Directory values(?,?,?,?,?,?,?,?,?,?,?)");
			
					ps.setString(1,date.getText());
					ps.setString(2,id.getText());
					ps.setString(3,name.getText());
					ps.setString(4,class1.getText());
					ps.setString(5,shift.getText());
					ps.setString(6,progress.getText());
					ps.setString(7,add.getText());
					ps.setString(8,city.getText());
					ps.setString(9,padd.getText());
					ps.setString(10,phno.getText());
					ps.setString(11,eadd.getText());
				                    ps.executeUpdate();
		jp.showMessageDialog(this,"Record Inserted Successfully","SUCCESS",jp.INFORMATION_MESSAGE);

				c.close();
				st.close();
			 }
			catch(ClassNotFoundException cnf)
			{
				System.out.println("Cnf Exception");
			}
			catch(SQLException sql)
			{
				jp.showMessageDialog(this,"Record Already Exists","EXCEPTION",jp.ERROR_MESSAGE);
			}
		}
		if(str1.equals("Delete"))
		{
			try
			{
				Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
			    Connection c = DriverManager.getConnection("jdbc:odbc:Student");
			    Statement st = c.createStatement();
			    PreparedStatement ps=c.prepareStatement("Delete from Directory where Id="+id.getText());
				ps.executeUpdate();
				jp.showMessageDialog(this,"Record Deleted Successfully","SUCCESS",jp.INFORMATION_MESSAGE);
				c.close();
				st.close();
			 }
			catch(ClassNotFoundException cnf)
			{
				System.out.println("Cnf Exception");
			}
			catch(SQLException sql)
			{
				jp.showMessageDialog(this,sql,"EXCEPTION",jp.ERROR_MESSAGE);

			}
		}
		if(str1.equals("Update"))
		{
		      try
		      {
			
			  Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
			    Connection c = DriverManager.getConnection("jdbc:odbc:Student");
			    Statement st = c.createStatement();
			//PreparedStatement ps=c.prepareStatement ("Update Directory set  Date=?,Name=?,Class=?,Shift=?,Progress=?,Address=?,City=?,Permenent_Address=?,PhoneNo=?,eaddress=?  where Id="+id.getText());
		PreparedStatement ps=c.prepareStatement ("Update Directory set Name=?, Class=?, Shift=?, Progress=?, Address=?, City=?, Permenent_Address=?, PhoneNo=?, eaddress=?, DateToday=? where Id="+id.getText());
					
					ps.setString(1,name.getText());		
					ps.setString(2,class1.getText());
					ps.setString(3,shift.getText());
					ps.setString(4,progress.getText());
					ps.setString(5,add.getText());
					ps.setString(6,city.getText());
					ps.setString(7,padd.getText());
					ps.setString(8,phno.getText());
					ps.setString(9,eadd.getText());
					ps.setString(10,date.getText());
					ps.executeUpdate();
				jp.showMessageDialog(this,"Record Updated Successfully","SUCCESS",jp.INFORMATION_MESSAGE);
				c.close();
				st.close();
			 }
			catch(ClassNotFoundException cnf)
			{
				System.out.println("Cnf Exception");
			}
			catch(SQLException sql)
			{
				jp.showMessageDialog(this,sql,"EXCEPTION",jp.ERROR_MESSAGE);
			}
		}
		if(str1.equals("Exit"))
		{
			System.exit(0);
		}
	  }
		
	public static void main(String arg[])
 	{
 		 ProjectLibrary p4 = new ProjectLibrary();
		 p4.setResizable(false);

	 }

}

⌨️ 快捷键说明

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