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

📄 database.java

📁 实现PKI/CA的数字签名部分
💻 JAVA
字号:
package dssserver;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;


public class DataBase {
	Connection con;
	Statement stmt;
	ResultSet rs;
	boolean checkuser(Client s){       //检查用户  
		String password = new String();
		try{
			try{		
				Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
			}
			catch(java.lang.ClassNotFoundException e){
				System.out.println("没有找到驱动类:");
				System.out.println(e.getMessage());
			}
			con = DriverManager.getConnection("jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=userinformation","sa","ccjin");
			stmt = con.createStatement();
			rs = stmt.executeQuery(" Select * From userinfo Where name='"+s.name+"'");
			rs.next();
			password = rs.getString(2);
			con.close();		 		 		 		 		
		}		
		catch(SQLException ex){
			if(ex!=null){
				System.out.println("数据库异常被捕获");
				System.out.println(ex.getSQLState());
				System.out.println(ex.getMessage());
				System.out.println(ex.getErrorCode());
			}
		}								
		if(s.pswd.equals(password)){
			return(true);		 	
		}
		else{
			return(false);		 	
		}
	}
	
	
	boolean checkuser(String loginname,String loginpswd){       //服务器登录
		String password = new String();
		try{
			try{		
				Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
			}
			catch(java.lang.ClassNotFoundException e){
				System.out.println("没有找到驱动类:");
				System.out.println(e.getMessage());
			}
			con = DriverManager.getConnection("jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=userinformation","sa","ccjin");
			stmt = con.createStatement();
			rs = stmt.executeQuery(" Select * From serveruser Where logname='"+loginname+"'");
			rs.next();
			password = rs.getString(2);
			con.close();		 		 		 		 		
		}		
		catch(SQLException ex){
			if(ex!=null){
				System.out.println("数据库异常被捕获");
				System.out.println(ex.getSQLState());
				System.out.println(ex.getMessage());
				System.out.println(ex.getErrorCode());
			}
		}								
		if(loginpswd.equals(password)){
			return(true);		 	
		}
		else{
			return(false);		 	
		}
	}
		
	void reguser(String name,String pswd){     //用户注册   
		try{
			try{
				Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
			}
			catch(java.lang.ClassNotFoundException e){
				System.out.println("没有找到驱动类:");
				System.out.println(e.getMessage());
			}
			con = DriverManager.getConnection("jdbc:microsoft:sqlserver://127.0.0.1:1433;DatabaseName=userinformation","sa","ccjin");
			stmt = con.createStatement();
			stmt.executeUpdate("Insert Into userinfo Values('"+name+"','"+pswd+"')");
			con.close();
		}		
		catch(SQLException ex){
			if(ex!=null){
				System.out.println("数据库异常被捕获");
				System.out.println(ex.getSQLState());
				System.out.println(ex.getMessage());
				System.out.println(ex.getErrorCode());
			}
		}		 		
	}
}

⌨️ 快捷键说明

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