Chinaunix首页 | 论坛 | 博客
  • 博客访问: 95557
  • 博文数量: 32
  • 博客积分: 2144
  • 博客等级: 大尉
  • 技术积分: 370
  • 用 户 组: 普通用户
  • 注册时间: 2008-10-25 09:28
文章分类

全部博文(32)

文章存档

2011年(6)

2010年(2)

2009年(10)

2008年(14)

我的朋友

分类: Java

2009-10-15 20:17:33

vista下servlet连sql server2000成功
 

package com.tsinghua;
import javax.servlet.http.*;
import javax.servlet.*;
import java.io.*;
import java.sql.*;

public class LoginCl extends HttpServlet
{
    public static void main(String[] args)
    {
        // main fun

    }
    public void doGet(HttpServletRequest req,HttpServletResponse res)
    {
        this.doPost(req,res);
    }
    Connection ct = null;
    Statement sm = null;
    ResultSet rs = null;
    public void doPost(HttpServletRequest req,HttpServletResponse res)
    {
        String u = req.getParameter("user");    
        String p = req.getParameter("passwd");
        try
        {
            Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
            ct = DriverManager.getConnection("jdbc:odbc:db","","");
            sm = ct.createStatement();
            rs =sm.executeQuery("select top 1 * from table1 where db_user = '" + u + "'");
            if(rs.next())
            {
                res.sendRedirect("wel?user=" + u + "&passwd="+p);
                HttpSession hs = req.getSession(true);
                hs.setMaxInactiveInterval(20);
                hs.setAttribute("pass","ok");
            }        
        }
        catch(Exception e)
        {
            e.printStackTrace();
        }
        finally
        {
            try
            {
                rs.close();
                sm.close();
                ct.close();    
            }
            catch(Exception ee)
            {
                ee.printStackTrace();
            }            
        }    
    }
}


阅读(729) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~