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

📄 usermgr.java

📁 同学编写的文件共享系统,内附使用说明,包含java大多数知识,适合初学者结合课本进行实践
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
	  {
	  	int i=-1;
	  
	  	try 
		  {//加载驱动程序,此处为JDBC-ODBC桥
		     Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
		     //指定连接的ODBC数据源为:"management"
		     String source="jdbc:odbc:management";
		       //通过驱动程序管理器建立与数据源的连接
		     Connection con=DriverManager.getConnection(source);
		       //创建执行查询的Statement对象
		      Statement stmt=con.createStatement();
			   String sql1="UPDATE User SET Password= "+newPassword+" WHERE Name= '"+name+"'";
			      i=stmt.executeUpdate(sql1);
		      stmt.close();
		      con.close();
		  }
		  catch(ClassNotFoundException e)
		   {
		   System.out.println("error:ClassNotFound"+e);
		    }
		    catch(SQLException e)
	        {
	  	    System.out.println("error:updateInfor_Password"+ e);
	        } 
		    //System.out.println("updateInfor_Password,done!!" );
	     }
	 
	 public void updateInfor_Quit( String name)  //下线
	  {
	  	int i=-1;  
	  	try 
		  {//加载驱动程序,此处为JDBC-ODBC桥
		     Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
		     //指定连接的ODBC数据源为:"management"
		     String source="jdbc:odbc:management";
		       //通过驱动程序管理器建立与数据源的连接
		     Connection con=DriverManager.getConnection(source);
		       //创建执行查询的Statement对象
		      Statement stmt=con.createStatement();
			   String sql2="UPDATE User SET onLine= 0 WHERE Name= '"+name+"'";
			   i=stmt.executeUpdate(sql2);
		      stmt.close();
		      con.close();
		  }
		  catch(ClassNotFoundException e)
		   {
		   System.out.println("error:ClassNotFound"+e);
		    }
		    catch(SQLException e)
	        {
	  	    System.out.println("error:updateInfor_Quit"+ e);
	        } 
		    //System.out.println("updateInfor_Quit,done!!" );
	     }
	 
	 
	 public void updateInfor_Load( String name)  //上线
	  {
	  	int i=-1;
	  
	  	try 
		  {//加载驱动程序,此处为JDBC-ODBC桥
		     Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
		     //指定连接的ODBC数据源为:"management"
		     String source="jdbc:odbc:management";
		       //通过驱动程序管理器建立与数据源的连接
		     Connection con=DriverManager.getConnection(source);
		       //创建执行查询的Statement对象
		      Statement stmt=con.createStatement();
			   String sql2="UPDATE User SET onLine= 1 WHERE Name= '"+name+"'";
			   i=stmt.executeUpdate(sql2);
		      stmt.close();
		      con.close();
		  }
		  catch(ClassNotFoundException e)
		   {
		   System.out.println("error:ClassNotFound"+e);
		    }
		    catch(SQLException e)
	        {
	  	    System.out.println("error:updateInfor_Load"+ e);
	        } 
		    //System.out.println("updateInfor_Load,done!!" );
	     }
	 
	
	 
	 public void updateInfor_M(String name,long aMoney)//修改金钱
	  {
	  	int i=-1;
	  	long money=selectInfor_M(name)+aMoney;
	  	try 
		  {//加载驱动程序,此处为JDBC-ODBC桥
		     Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
		     //指定连接的ODBC数据源为:"management"
		     String source="jdbc:odbc:management";
		       //通过驱动程序管理器建立与数据源的连接
		     Connection con=DriverManager.getConnection(source);
		       //创建执行查询的Statement对象
		      Statement stmt=con.createStatement();
		      //System.out.println(money);
		      String sql="UPDATE User SET moneyn= "+money+" WHERE Name= '"+name+"'";
		      i=stmt.executeUpdate(sql);
		      
		      stmt.close();
		      con.close();
		  }
		  catch(ClassNotFoundException e)
		   {
		   System.out.println("error:update_Money_ClassNotFound"+e);
		    }
		    catch(SQLException e)
	        {
	  	    System.out.println("error:update_Money"+ e);
	        } 
		    //System.out.println("金钱修改成功");
		    
	     }
	 
	 
	 
	 public int checkUser(String name,long password)//核对密码
	 {
	 	if(selectInfor_PS(name)==0)return 0;
	 	else if(selectInfor_PS(name)==password)
	 	return 1;
	 	else return -1;
	 	}
	 
	 
	 
	 
	 public long selectInfor_PS(String name)//查找某个用户的信息(密码)(没有找到则返回0)
	 {
	 	
	 	long password=0;
	 	try 
		  {//加载驱动程序,此处为JDBC-ODBC桥
		     Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
		     //指定连接的ODBC数据源为:"management"
		     String source="jdbc:odbc:management";
		       //通过驱动程序管理器建立与数据源的连接
		     Connection con=DriverManager.getConnection(source);
		       //创建执行查询的Statement对象
		      Statement stmt=con.createStatement();
			   
			   String sql="SELECT * FROM User WHERE Name= '"+name+"'";
			   ResultSet rs =stmt.executeQuery(sql); 
			   if(rs.next())
			   {password=rs.getLong("Password");}
			    stmt.close();
		        con.close();
		  }
		  catch(ClassNotFoundException e)
		   {
		   System.out.println("error:ClassNotFound_GetInfor_Password"+e);
		    }
		    catch(SQLException e)
	      {
		    System.out.println("error:GetInfor_Password"+ e);
	      } 
		    return password;
	   }
	 
	 
	 public int selectInfor_OL(String name)//查找某个用户的信息(在线状态)(没有找到则返回0)
	 {
	 	
	 	int onLine=0;
	 	try 
		  {//加载驱动程序,此处为JDBC-ODBC桥
		     Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
		     //指定连接的ODBC数据源为:"management"
		     String source="jdbc:odbc:management";
		       //通过驱动程序管理器建立与数据源的连接
		     Connection con=DriverManager.getConnection(source);
		       //创建执行查询的Statement对象
		      Statement stmt=con.createStatement();
			   
			   String sql="SELECT * FROM User WHERE Name= '"+name+"'";
			   ResultSet rs =stmt.executeQuery(sql); 
			   if(rs.next())
			   {onLine=rs.getInt(4);}
			    stmt.close();
		        con.close();
		  }
		  catch(ClassNotFoundException e)
		   {
		   System.out.println("error:ClassNotFound_GetInfor_Password"+e);
		    }
		    catch(SQLException e)
	      {
		    System.out.println("error:GetInfor_Password"+ e);
	      } 
		    //System.out.println(onLine);
		    return onLine;
	   }
	 public long selectInfor_StartT(String name)//查找某个用户的信息(在线状态)(没有找到则返回0)
	 {
	 	
	 	long  startTime=0;
	 	try 
		  {//加载驱动程序,此处为JDBC-ODBC桥
		     Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
		     //指定连接的ODBC数据源为:"management"
		     String source="jdbc:odbc:management";
		       //通过驱动程序管理器建立与数据源的连接
		     Connection con=DriverManager.getConnection(source);
		       //创建执行查询的Statement对象
		      Statement stmt=con.createStatement();
			   
			   String sql="SELECT * FROM User WHERE Name= '"+name+"'";
			   ResultSet rs =stmt.executeQuery(sql); 
			   if(rs.next())
			   {startTime=rs.getLong(5);}
			    stmt.close();
		        con.close();
		  }
		  catch(ClassNotFoundException e)
		   {
		   System.out.println("error:ClassNotFound_GetInfor_Password"+e);
		    }
		    catch(SQLException e)
	      {
		    System.out.println("error:GetInfor_Password"+ e);
	      } 
		    //System.out.println(onLine);
		    return startTime;
	   }
	 
	 
	 public void updateInfor_StartT(long startTime, String name)/*修改下线时间(可调用getTim()函数
                                                                        修改下线时间用来计算在线时长)*/  
	 	{
	  	int i=-1;
	  
	  	try 
		  {//加载驱动程序,此处为JDBC-ODBC桥
		     Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
		     //指定连接的ODBC数据源为:"management"
		     String source="jdbc:odbc:management";
		       //通过驱动程序管理器建立与数据源的连接
		     Connection con=DriverManager.getConnection(source);
		       //创建执行查询的Statement对象
		      Statement stmt=con.createStatement();
			   String sql1="UPDATE User SET startTime= "+startTime+" WHERE Name= '"+name+"'";
			      i=stmt.executeUpdate(sql1);
		      stmt.close();
		      con.close();
		  }
		  catch(ClassNotFoundException e)
		   {
		   System.out.println("error:ClassNotFound_Update_Infor_StartTime"+e);
		    }
		    catch(SQLException e)
	        {
	  	    System.out.println("error:Update_Infor_StartTime"+ e);
	        } 
		    //System.out.println("Update_Infor_StartTime成功" );
	   }
	 
	 public long selectInfor_M(String name)//查找某个用户的信息(金钱数)
	 {
	 	
	 	long money=0;
	 	try 
		  {//加载驱动程序,此处为JDBC-ODBC桥
		     Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
		     //指定连接的ODBC数据源为:"management"
		     String source="jdbc:odbc:management";
		       //通过驱动程序管理器建立与数据源的连接
		     Connection con=DriverManager.getConnection(source);
		       //创建执行查询的Statement对象
		      Statement stmt=con.createStatement();
			   
			   String sql="SELECT * FROM User WHERE Name= '"+name+"'";
			   ResultSet rs =stmt.executeQuery(sql); 
			   if(rs.next())
			   {money=rs.getLong("moneyn");}
			    stmt.close();
		        con.close();
		  }
		  catch(ClassNotFoundException e)
		   {
		   System.out.println("error:ClassNotFound"+e);
		    }
		    catch(SQLException e)
	      {
		    System.out.println("error:select_Money"+ e);
	      } 
		    return money;
	   }
	 
	 
	 public void updateInfor_EndT(long endTime, String name)/*修改下线时间(可调用getTim()函数
	                                                                 修改下线时间用来计算在线时长)*/
	  {
	  	int i=-1;
	  
	  	try 
		  {//加载驱动程序,此处为JDBC-ODBC桥
		     Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
		     //指定连接的ODBC数据源为:"management"
		     String source="jdbc:odbc:management";
		       //通过驱动程序管理器建立与数据源的连接
		     Connection con=DriverManager.getConnection(source);
		       //创建执行查询的Statement对象
		      Statement stmt=con.createStatement();
			   String sql1="UPDATE User SET endTime= "+endTime+" WHERE Name= '"+name+"'";
			      i=stmt.executeUpdate(sql1);
		      stmt.close();
		      con.close();
		  }
		  catch(ClassNotFoundException e)
		   {
		   System.out.println("error:ClassNotFound"+e);
		    }
		    catch(SQLException e)
	        {
	  	    System.out.println("error:UPDATE_Infor_endTime"+ e);
	        } 
		   //System.out.println("UPDATE_Infor_endTime,done!!" );
	     }
}

⌨️ 快捷键说明

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