1031学习记录

package com.company;

import java.sql.*;

public class Main {




    public static void DelEmp(int deptno) throws ClassNotFoundException, SQLException
    {
        Connection con = DbUtils.GetConnection();

        //获得statement对象(执行sql语句)
        Statement st=con.createStatement();
        //查询或者更新
        String strsql="DELETE from emp WHERE deptno=" + deptno;
        //处理结果
        st.executeUpdate(strsql);
        //关闭连接

        DbUtils.Close(con, st);
    }



    public static void UpdateDept(Dept dept) throws ClassNotFoundException, SQLException
    {
        Connection con = DbUtils.GetConnection();
        //获得statement对象(执行sql语句)
        Statement st=con.createStatement();
        //查询或者更新
        String strSql = "update dept set dname = '"+ dept.getStrDeptName() +"' where deptno = " + dept.getnDept();
        //处理结果
        st.executeUpdate(strSql);
        //关闭连接

        DbUtils.Close(con, st);
    }
    public static void InsertUser() throws ClassNotFoundException, SQLException
    {
        Connection con = DbUtils.GetConnection();
        //获得statement对象(执行sql语句)
        Statement st=con.createStatement();
        //查询或者更新
        String strSql = "insert into userinfo values(sequser.nextval,'neusoft','123')";
        //处理结果
        st.executeUpdate(strSql);
        //关闭连接

        DbUtils.Close(con, st);
    }

    public static int login(String strName, String strPass) throws ClassNotFoundException, SQLException
    {
        Connection con = DbUtils.GetConnection();
        //获得statement对象(执行sql语句)
      //  Statement st=con.createStatement();
        //查询或者更新
        String strSql = "select * from userinfo where username = ? and password = ?";

        PreparedStatement ps = con.prepareStatement(strSql);
        ps.setString(1,strName);
        ps.setString(2,strPass);
        //处理结果
        ResultSet rs = ps.executeQuery();
        int nResult = 0;
        if(rs.next())
        {
            nResult = 1;
        }
        //关闭连接
        DbUtils.CloseEx(con, ps, rs);
        return nResult;
    }
    public static void main(String[] args) throws ClassNotFoundException, SQLException
    {
        Dept dept = new Dept();
        dept.setnDept(20);
        dept.setStrDeptLoc("beijing");
        dept.setStrDeptName("测试部");
        UpdateDept(dept);
//        int n = login("neusoft", "123");
//        if(n>0)
//        {
//            System.out.println("登录成功");
//        }
//        else
//        {
//            System.out.println("登录失败");
//        }
    }
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值