package javaDao;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Vector;
import javaLoginInf.AdminInf;
import javaLoginInf.LoginInf;
import javaLoginInf.StudentStaff;
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author fanglin
*/
public class Dao {
protected static String dbClassName="com.microsoft.sqlserver.jdbc.SQLServerDriver";
protected static String dbUr1="jdbc:sqlserver://localhost:1433;DatabaseName=Manage2";
protected static String dbUser="sa";
protected static String dbPwd="123456";
protected static String second=null;
private static Connection conn=null;
private Dao(){
try {
if (conn==null) {
Class.forName(dbClassName);
conn= DriverManager.getConnection(dbUr1, dbUser,dbPwd);
}
else
return;
}
catch (Exception ee){
ee.printStackTrace();
}
}
public static ResultSet executeQuery(String sql){
try{
if(conn==null)
new Dao();
return conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,
ResultSet.CONCUR_UPDATABLE).executeQuery(sql);
}catch(SQLException e){
e.printStackTrace();
return null;
}finally{
}
}
public static int executeUpdate(String sql){
try{
if(conn==null)
new Dao();
return conn.createStatement().executeUpdate(sql);
}catch (SQLException e){
System.out.println(e.getMessage());
return -1;
}
}
//检查用户名和密码是否存在
public static boolean CheckLoginInf(LoginInf li){
String sql = "select * from Login where name='"+li.getName()+"' and password='"+li.getPwd()+"'";
ResultSet rs = Dao.executeQuery(sql);
try{
if(rs.next()){
return true;
}else{
return false;
}
}catch(Exception e){
e.printStackTrace();
return false;
}
}
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Vector;
import javaLoginInf.AdminInf;
import javaLoginInf.LoginInf;
import javaLoginInf.StudentStaff;
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author fanglin
*/
public class Dao {
protected static String dbClassName="com.microsoft.sqlserver.jdbc.SQLServerDriver";
protected static String dbUr1="jdbc:sqlserver://localhost:1433;DatabaseName=Manage2";
protected static String dbUser="sa";
protected static String dbPwd="123456";
protected static String second=null;
private static Connection conn=null;
private Dao(){
try {
if (conn==null) {
Class.forName(dbClassName);
conn= DriverManager.getConnection(dbUr1, dbUser,dbPwd);
}
else
return;
}
catch (Exception ee){
ee.printStackTrace();
}
}
public static ResultSet executeQuery(String sql){
try{
if(conn==null)
new Dao();
return conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,
ResultSet.CONCUR_UPDATABLE).executeQuery(sql);
}catch(SQLException e){
e.printStackTrace();
return null;
}finally{
}
}
public static int executeUpdate(String sql){
try{
if(conn==null)
new Dao();
return conn.createStatement().executeUpdate(sql);
}catch (SQLException e){
System.out.println(e.getMessage());
return -1;
}
}
//检查用户名和密码是否存在
public static boolean CheckLoginInf(LoginInf li){
String sql = "select * from Login where name='"+li.getName()+"' and password='"+li.getPwd()+"'";
ResultSet rs = Dao.executeQuery(sql);
try{
if(rs.next()){
return true;
}else{
return false;
}
}catch(Exception e){
e.printStackTrace();
return false;
}
}