日期:2014-05-16 浏览次数:20410 次
package com.jie.java.phone; import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpSession; public class login { public static HttpSession session=null; public static final String username="abin"; public static final String password="abing"; public static void main(String args[]){ boolean result=checkuser(username,password,session); System.out.println(result+":-------:数据库验证成功"); } public static Connection getConn(){ Connection conn=null; try{ Class.forName("com.ibm.db2.jcc.DB2Driver"); String url="jdbc:db2://localhost:50000/connect"; conn=DriverManager.getConnection(url,"acer","abin"); }catch(Exception e){ e.printStackTrace(); System.out.println("数据库连接失败"); } return conn; } public static boolean checkuser(String username,String password,HttpSession session){ boolean result=false; try{ String sql="select * from connect where username='"+username+"' and password='"+password+"'"; ResultSet rs=login.getConn().createStatement().executeQuery(sql); if(rs.next()){ result=true; // System.out.println("dfsaf"); // session.setAttribute("username", rs.getString("username")); } }catch(Exception e){ e.printStackTrace(); } return result; } }