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("登录失败"); // } } }
1031学习记录
最新推荐文章于 2024-05-04 08:51:49 发布