用户管理系统cmd版

 

 

1.用户登录

    1.1提示输入用户名和密码。

    1.2如果登录成功,显示主窗体+显示权限。

       1.2.1查询信息(权限:1.普通用户:查询自己信息;2.管理员:按用户名模糊查询;)

       1.2.2修改信息(权限:1.普通用户:修改自己信息;2.管理员:按用户名模糊查询后修改查询出的结果信息;)

    1.3如果失败,显示用户名或密码错误,并显示1

    1.4退出程序

2.用户注册(*用户注册只能注册普通权限,管理员权限由管理员来赋予)

    2.1用户注册界面显示,提示输入用户名,密码,邮箱。

       2.1.1用户名,密码,邮箱的check

           2.1.1.1检查成功,登录数据库,提示成功信息,并显示1.1

           2.1.1.2检查失败,给出错误信息,并显示2.1

    2.2退出程序

3.退出程序

 

 

 

 

 

-- Create table

create table USERINFO

(

  name     VARCHAR2(20),

  password VARCHAR2(20),

  email    VARCHAR2(20),

  power    NUMBER default 0

)

tablespace USERS

  pctfree 10

  initrans 1

  maxtrans 255

  storage

  (

    initial 64

    minextents 1

    maxextents unlimited

  )

 

--系统超级管理员

insert into userinfo values(

    zhang,

    123456,

    zys@163.com,

    1

 

 

)

 

 

 

;

 

 

 

 

Index.java                                                      

 

 

package com.zys.web;

//本类为系统入口

publicclass Index {

publicstaticvoid main(String[] args) {

    Home.show();         //本系统主页

}

}

 

 

 

 

 

 

 

 

 

Home.java

 

package com.zys.web;

 

import java.util.Scanner;

 

import com.zys.service.Service;

 

public class Home {

              //获取控制台输入权

        

               static Service service=new Service();

             

              public static void show(){

                     //用户管理系统主页面

                     System.out.println("=================欢迎进入用户管理系统=================");

                     System.out.println("请选择要操作的类型,输入对应的数字:");

                     System.out.println("1.用户登录");

                     System.out.println("2.用户注册");

                     System.out.println("3.退出程序");

                     System.out.println("=====================================================");

                     Scanner in=new Scanner(System.in);

                     try{

                     int i=in.nextInt();    //获取操作数1,2,3;并处理。

                     switch (i) {

                     case 1:

                            service.login();          //调用servicelogin方法进行登录界面

                            break;

                     case 2:

                            service.addUser();       //调用serviceaddUser方法添加用户界面

                            break;

                     case 3:

                            System.exit(0);

                            break;

                     default:

                            System.err.println("输入错误!请按提示输入!");

                            try {

                                   Thread.sleep(500);

                            } catch (InterruptedException e1) {

                                   e1.printStackTrace();

                            }

                            show();

                            break;

                     }

                     }catch(Exception e){

                            System.err.println("输入错误!请按提示输入!");

                            try {

                                   Thread.sleep(500);

                            } catch (InterruptedException e1) {

                                   e1.printStackTrace();

                            }

                            show();

                           

                     }

              }

}

 

 

 

 

 

 

 

 

 

AlterService.java

 

 

package com.zys.service;

 

import java.sql.Connection;

import java.sql.ResultSet;

import java.sql.SQLException;

import java.sql.Statement;

import java.util.Scanner;

 

import com.zys.Dao.JdbcOracle;

 

public class AlterService {

//修改用户名

                            public static void alterName(String name ){

                                   //连接数据库

                                   Connection con=JdbcOracle.connect();

                                   Statement st=null;

                                   ResultSet rs=null;

                                  

                                   System.out.println("你要修改 "+name+" 的用户名!");

                                   System.out.println("输入新的姓名,回车结束:");

                                   Scanner in=new Scanner(System.in); //获取输入的新姓名

                                   String newname=in.next();

                                   boolean flag=false;

                                   try {

                                          st=con.createStatement();

                                                 //检查用户名合法性

                                          String sql="select * from userinfo where name='"+newname+"'";

                                          rs=st.executeQuery(sql);

                                          if(rs.next()){      //验证用户名是否存在

                                                         System.err.println("用户名已存在!");

                                                               alterName(name);

                                           }

                                          if(newname.length()<20){      //用户名检查

                                                 for(int j=0 ; j<newname.length(); j++){

                                                        if(newname.charAt(j)>='a'&&newname.charAt(j)<='z'||newname.charAt(j)>='A'&&newname.charAt(j)<='Z'){

                                                               flag=true;

                                                        }else{

                                                               System.err.println("用户名包含了非字母元素!");

                                                               alterName(name);

                                                               break;

                                                        }

                                                 }

                                          }else{

                                                 System.err.println("用户名过长,大于20个字母!");

                                                 alterName(name);

                                          }

                                  

                                                 //合法后操作

                                          if(flag){

                                                 String sql1="update userinfo  set name='"+newname+"'"+"where name='"+name+"'";

                                                 st.executeUpdate(sql1);

                                          }

                                  

                                         

                                          st.close();

                                          con.close();

                                          DbService.select(newname);

                                         

                                   } catch (SQLException e) {

                                         

                                          e.printStackTrace();

                                   }

                                  

                            }

//修改密码

                            public static void alterPassword(String name,String password ){

                                   Connection con=JdbcOracle.connect();

                                   Statement st=null;

                                  

                                   System.out.println("你要修改 "+name+" 的密码!");

                                   System.out.println("输入新的密码,回车结束:");

                                   Scanner in=new Scanner(System.in); //获取输入的新密码

                                   String newpassword=in.next();

                                   boolean flag=false;

                                   try {

                                          st=con.createStatement();

                                          if(newpassword.length()<20){       //密码检查

                                                 for(int k=0 ; k<newpassword.length();k++){

                                                        if(newpassword.charAt(k)>=48&&newpassword.charAt(k)<=57){

                                                               flag=true;

                                                        }else{

                                                               System.err.println("密码包含非数字元素!");

                                                               alterPassword(name, password);

                                                               break;

                                                        }

                                                 }

                                          }else{

                                                 System.err.println("密码长度大于20");

                                                 alterName(name);

                                          }

                                         

                                                 //合法后操作

                                          if(flag){

                                                 String sql1="update userinfo  set password='"+newpassword+"'"+" where name='"+name+"'";

                                                

                                                 st.executeUpdate(sql1);

                                                

                                          }

                                          st.close();

                                          con.close();

                                          DbService.select(name);

                                         

                                   } catch (SQLException e) {

                                         

                                          e.printStackTrace();

                                   }

                                                              

                     }

//修改邮箱

                            public static void alterEmail(String name ,String email ){

                                   Connection con=JdbcOracle.connect();

                                   Statement st=null;

                                   ResultSet rs=null;

                                  

                                   System.out.println("你要修改 "+name+" 的邮箱!");

                                   System.out.println("输入你的邮箱,回车结束:");

                                   Scanner in=new Scanner(System.in); //获取输入的新密码

                                   String newemail=in.next();

                                   boolean flag=false;

                                   try {

                                          st=con.createStatement();

                                           if(newemail.matches("\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*"))

                                           {

                                           flag=true;

                                           }

                                           else

                                           {

                                                  System.err.println("邮箱不合法!");

                                                  relax();

                                                 alterEmail(name, email);

                                           }

                                  

                                                 //合法后操作

                                          if(flag){

                                                 String sql1="update userinfo  set email='"+newemail+"'"+"where name='"+name+"'";

                                                 st.executeUpdate(sql1);

                                          }

                                          st.close();

                                          con.close();

                                          DbService.select(name);

                                         

                                   } catch (SQLException e) {

                                         

                                          e.printStackTrace();

                                   }

                                                

                            }

                           

                           

                           

//休眠

                            public static void relax(){

                                          try {

                                                 Thread.sleep(500);

                                          } catch (InterruptedException e) {

                                                 // TODO Auto-generated catch block

                                                 e.printStackTrace();

                                          }

                            }

}

 

 

 

 

 

DbService.java

 

 

package com.zys.service;

 

import java.sql.Connection;

import java.sql.ResultSet;

import java.sql.SQLException;

import java.sql.Statement;

import java.util.Scanner;

 

import com.zys.Dao.JdbcOracle;

 

public class DbService {

       /*此类包含有登录检查,注册检查即插入,查询全部,模糊查询,修改权限,

        * 删除操作

        * */

      

       //登录检查

       public static void loginCheck(String name , String password){

             

                                   //进行数据库连接

                                   Connection con=JdbcOracle.connect();

                                   Statement st=null;

                                   ResultSet rs=null;

                                   String sql="select * from userinfo where name='"+name+"'";

                                   try {

                                          st=con.createStatement();

                                          rs=st.executeQuery(sql);

                                          if(!rs.next()){      //验证用户名是否存在

                                                         System.err.println("查无此人!");//登录失败,返回登陆页面

                                                               Service.login();

                                           }else{   

                                                       String nam=rs.getString("name");

                                                       String pwd=rs.getString("password");   //获取密码与权限,备用(登陆成功后使用)。

                                                        int pow=rs.getInt("power"); 

                                                    //验证用户名与密码是否一致

                                                

                                                                if(pwd.equals(password)){

                                                                       System.out.println("登录成功!");

                                                                             loginSuccess(nam, pwd, pow);

                                                                       }else{

                                                                       System.err.println("登录失败!密码错误!");//登录失败,返回登陆页面

                                                                       Service.login();

                                                                       }

                                                       

                                     }

                                         

                                                        rs.close();

                                                        st.close();

                                                        con.close();

                                   } catch (SQLException e) {

                                          // TODO Auto-generated catch block

                                          e.printStackTrace();

                                   }

                                  

                                  

       }

      

       //注册检查

       public static void addCheck(String name, String password, String email ,int power) {

                                   // 合法性检测   是否重复?

                                   Connection con=JdbcOracle.connect();

                                  

                                   Statement st=null;

                                  

                                   String sql="select * from userinfo where name='"+name+"'";  //检查用户名是否重复

                                   boolean mark=true;

                                   try {

                                          st=con.createStatement();

                                          int i=st.executeUpdate(sql);

                                          if(i>0){

                                                 System.err.println("用户已存在,请重新注册!");

                                                 mark=false;

                                                 Service.addUser();

                                          }

                                          //关闭数据库

                                          st.close();

                                          con.close();

                                         

                                          //检查合法性

                                          if(name.length()<20){      //用户名检查

                                                 for(int j=0 ; j<name.length(); j++){

                                                        if(name.charAt(j)>='a'&&name.charAt(j)<='z'||name.charAt(j)>='A'&&name.charAt(j)<='Z'){

                                                               //System.out.println("用户名合法!");

                                                        }else{

                                                               System.err.println("用户名包含了非字母元素!");

                                                               mark=false;

                                                               Service.addUser();

                                                               break;

                                                        }

                                                 }

                                          }else{

                                                 System.err.println("用户名过长,大于20个字母!");

                                                 mark=false;

                                                 Service.addUser();

                                          }

                                          if(password.length()<20){       //密码检查

                                                 for(int k=0 ; k<password.length();k++){

                                                        if(password.charAt(k)>=48&&password.charAt(k)<=57){

                                                               //System.out.println("密码合法");

                                                        }else{

                                                               System.err.println("密码包含非数字元素!");

                                                               mark=false;

                                                               Service.addUser();

                                                               break;

                                                        }

                                                 }

                                          }else{

                                                 System.err.println("密码长度大于20");

                                                 mark=false;

                                                 Service.addUser();

                                          }

                                                 //邮箱检查

                    

                                           if(email.matches("\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*"))

                                           {

                                           ///System.out.println("邮箱合法!");

                                           }

                                           else

                                           {

                                                  System.err.println("邮箱不合法!");

                                                  mark=false;

                                                  Service.addUser();

                                           }

                                          //权限检查

                                          if(power==0){         

                                                 //System.out.println("权限合法!");

                                          }else{

                                                 System.err.println("权限非法,请输入0");

                                                 mark=false;

                                                 Service.addUser();

                                          }

                                         

                                          if(mark){

                                                 System.out.println("恭喜注册成功!跳入登录页面中...");

                                                 //调用数据插入方法

                                                 add(name,password , email , power);

                                                 //跳转到用户登录页面

                                                 Service.login();

                                          }else{

                                                 System.err.println("信息有误不可入库!");

                                          }

                                         

                                   } catch (SQLException e) {

                                          e.printStackTrace();

                                   }

                                  

       }

       //    添加用户信息到数据库

       public static void add(String name, String password, String email ,int power){

                                   //连接数据库

                                   Connection con=JdbcOracle.connect();

                                   Statement st=null;

                                  

                                   String sql="insert into userinfo values('"+name+"','"+password+"','"+email+"',"+power+")";

                                   try {

                                          st=con.createStatement();

                                          st.executeUpdate(sql);

                                         

                                          st.close();

                                          con.close();

                                   } catch (SQLException e) {

                                          System.out.println("插入数据失败!");

                                   }

       }

      

       public static void loginSuccess(String name ,String password ,int power){

                                   //普通用户

                                   if(power<1){

                                          Service.normalSuccess(name,power);

                                   }

                                   //管理员登录

                                   if(power>0){

                                          Service.managerSuccess(name,power);

                                   }

       }

       //查询个人信息

       public static void select(String name){

                                   //连接数据库

                                   Connection con=JdbcOracle.connect();

                                   Statement st=null;

                                   ResultSet rs=null;

                                   String sql="select * from userinfo where name='"+name+"'";

                                   try {

                                          st=con.createStatement();

                                          rs=st.executeQuery(sql);

                                          while(rs.next()){

                                                 int i=rs.getInt("power");

                                                 System.out.println("name: "+rs.getString("name")+"\tpassword: "+rs.getString("password")+"\temail: "

                                                               +rs.getString("email")+"\tpower: "+i);

                                                 if(i==1){

                                                 Service.managerSuccess(name, i);

                                                 }if(i==0){

                                                        Service.normalSuccess(name, i);

                                                 }

                                          }

                                         

                                          st.close();

                                          rs.close();

                                          con.close();

                                         

                                   } catch (SQLException e) {

                                          System.err.println("查询个人数据失败!");

                                   }

       }

       //查询全部数据

       public static void selectAll(String name ,int power){

                                   //连接数据库

                                   Connection con=JdbcOracle.connect();

                                   Statement st=null;

                                   ResultSet rs=null;

                                   String sql="select * from userinfo ";

                                   try {

                                          st=con.createStatement();

                                          rs=st.executeQuery(sql);

                                          while(rs.next()){

                                                 System.out.println("name: "+rs.getString("name")+"\tpassword: "+rs.getString("password")+"\temail: "

                                                               +rs.getString("email")+"\tpower: "+rs.getInt("power"));

                                          }

                                         

                                          st.close();

                                          rs.close();

                                          con.close();

                                          Service.managerSuccess(name ,power);

                                   } catch (SQLException e) {

                                          System.err.println("查询全部数据失败!");

                                   }

       }

      

       //按姓名模糊查询

       public static void selectByName(String name ,int power){

                                   //连接数据库

                                   Connection con=JdbcOracle.connect();

                                   Statement st=null;

                                   ResultSet rs=null;

                                   Scanner in=new Scanner(System.in); //获取输入的模糊姓名

                                   System.out.println("请输入用户名的全部或部分,回车确认:");

                                   String nam=in.next();

                                   String sql="select * from userinfo where name like '%"+nam+"%'";

                                   System.out.println("如果无匹配项则不显示!");

                                   try {

                                          st=con.createStatement();

                                          rs=st.executeQuery(sql);

//                                        if(!rs.next()){      //判断是否存在

//                                               System.out.println("查无此人!");

//                                        }else{

                                  

                                            while(rs.next()){  //存在即输出

                                         

                                                 System.out.println("name: "+rs.getString("name")+"\tpassword: "+rs.getString("password")+"\temail: "

                                                               +rs.getString("email")+"\tpower: "+rs.getInt("power"));

                                                  

                                            }

//                                        }

                                          st.close();

                                          rs.close();

                                          con.close();

                                          Service.managerSuccess(name, power);

                                   } catch (SQLException e) {

                                          System.err.println("模糊查询失败!");

                                   }

}

       //修改用户数据

       public static void update(String name ){

                                   //连接数据库

                                   Connection con=JdbcOracle.connect();

                                   Statement st=null;

                                   ResultSet rs=null;

                                   Scanner in=new Scanner(System.in); //获取输入的姓名

                                   System.out.println("当前用户为:"+name);

                                  

                                   System.out.println("请输入要修改的用户名,回车确认:");

                                   String nam=in.next();

                                   String man="zhang";

                                   if(nam.equals(man)){

                                         

                                          System.err.println("身份为系统总管理员,信息不可修改!");

                                          try {

                                                 Thread.sleep(500);

                                   } catch (InterruptedException e1) {

                                                 e1.printStackTrace();

                                          }

                                          update(name);

                                   }else{

                                          alterUser(nam);

                                   }

                                  

       }

      

      

       //修改个人信息

       public static void alterUser(String name){

                                   System.out.println("=================欢迎进入信息修改页面=================");

                                   System.out.println("当前用户为:"+name);

                                   System.out.println("请按页面提示进行操作:");

                                   System.out.println("1.修改用户名");

                                   System.out.println("2.修改密码");

                                   System.out.println("3.修改邮箱");

                                   System.out.println("4.退出系统");

                                   Connection con=JdbcOracle.connect();

                                   Statement st=null;

                                   ResultSet rs=null;

                                   String sql="select * from userinfo where name='"+name+"'";

                                   Scanner in=new Scanner(System.in); //获取输入权

                                  

                                   try {

                                          st=con.createStatement();

                                          rs=st.executeQuery(sql);

                                          rs.next();

                                          String nam=rs.getString("name");

                                          String paw=rs.getString("password");

                                          String ema=rs.getString("email");

                                          try{

                                          int i =in.nextInt();

                                          switch (i) {

                                          case 1:

                                                 AlterService.alterName(nam);

                                                 break;

                                          case 2:

                                                 AlterService.alterPassword(nam, paw);

                                                 break;

                                          case 3:

                                                 AlterService.alterEmail(nam, ema);      

                                                 break;

                                          case 4:

                                                        System.exit(0);     

                                                 break;

                                          default:

                                                 System.out.println("输入非法,请按提示操作!");

                                                 AlterService.relax();

                                                 alterUser(nam);

                                                 break;

                                          }

                                          }catch(Exception e){

                                                 System.out.println("输入非法,请按提示操作!");

                                                 AlterService.relax();

                                                 alterUser(nam);

                                          }

                                          rs.close();

                                          st.close();

                                          con.close();

                                   } catch (SQLException e) {

                                          // TODO Auto-generated catch block

                                          e.printStackTrace();

                                   }

       }

      

      

      

      

      

      

      

      

      

      

      

      

      

      

       //修改权限

       public static void changePower(String name , int power){

                                   Connection con=JdbcOracle.connect();

                                   Statement st=null;

                                  

                                   Scanner in=new Scanner(System.in); //获取输入的权限值

                                   System.out.println("当前用户为:"+name+"\t权限为"+power+"\t0为无权限1为有权限)");

                                  

                                   try {

                                          System.out.println("输入被赋权的用户名,回车确认:");

                                          String na=in.next();

                                          System.out.println("输入新的权限值,回车确认:");

                                          int i=in.nextInt();

                                          String sql1="select * from userinfo where name='"+na+"'";

                                          st=con.createStatement();

                                          int ch=st.executeUpdate(sql1);

                                          if(ch==0){

                                                 System.err.println("用户不存在,请重新赋权!");

                                                 Service.managerSuccess(name, power);

                                          }else{

                                          String sql="update userinfo set power="+i+" where name='"+na+"'";

                                          System.out.println(sql);

                                         

                                          st.executeUpdate(sql);

                                          selectAll(name ,power);

                                          Service.managerSuccess(name, power);

                                          st.close();

                                          con.close();

                                          }

                                   } catch (Exception e) {

                                          System.out.println("该用户不存在!");

                                          Service.managerSuccess(name, power);

                                   }

       }

      

}

 

 

 

 

 

Service.java

 

 

package com.zys.service;

 

import java.util.Scanner;

 

publicclass Service {

 

       //用户登录

       publicstaticvoid login(){

           Scanner in=new Scanner(System.in); //获取输入权

           //用户登录主页面

              System.out.println("=================欢迎进入用户登录信息输入页面=================");

              System.out.println("请按页面提示进行操作:");

              System.out.println("输入2退出程序!");

              System.out.println("请输入用户名,回车确认:");

              String name=in.next();

              System.out.println("请输入密码,回车确认:");

              String password=in.next();

             

              DbService.loginCheck(name, password); 

             

              System.out.println("=====================================================");

              //获取用户名和密码,进行数据库匹配检查;

           System.out.println("请输入2退出...");  

           try{int i=in.nextInt(); //获取操作数2 ;并处理

           switch (i) {

              case 2:

              System.exit(0);         //退出程序

                  break;

              default:

                  break;

              }

           }catch(Exception e){

              System.out.println("输入非法!");

              Service.login();

           }

             

       }

      

       //用户注册

       publicstaticvoid addUser(){

           //用户注册主页面

           System.out.println("=================欢迎进入用户注册页面=================");

           System.out.println("请按页面提示进行操作:");

           System.out.println("输入2退出程序!");

           System.out.println("请输入用户名,回车确认:");

           Scanner in=new Scanner(System.in); //获取输入权

           String name=in.next();

           System.out.println("请输入密码,回车确认:");

           String password=in.next();

           System.out.println("请输入邮箱,回车确认:");

           String email=in.next();

           System.out.println("请输入0,回车确认:");

           int power=in.nextInt();

           //获取用户名,密码,邮箱进行合法性检查;

           DbService.addCheck(name, password ,email,power);

           System.out.println("=====================================================");

           try{int i=in.nextInt(); //获取操作数2 ;并处理

           switch (i) {

           case 2:

              System.exit(0);         //退出程序

              break;

           default:

              break;

           }

           }catch(Exception  e){

              System.out.println("输入非法!");

              Service.addUser();

           }

       }

       publicstaticvoid normalSuccess(String name,int power){

           //普通用户登陆成功页面

           System.out.println("=================欢迎进入登录成功页面=================");

           System.out.println("当前用户为:"+name+"\t权限为"+power+"\t0为无权限1为有权限)");

           System.out.println("请按页面提示进行操作:");

           System.out.println("1.查询个人信息");

           System.out.println("2.修改个人信息");

           System.out.println("3.退出系统");

           Scanner in=new Scanner(System.in); //获取输入权

           try {

              int i=in.nextInt();

              switch (i) {

              case 1:

                  DbService.select(name);

                  break;

              case 2:

             

                  DbService.alterUser(name);

                  break;

              case 3:

                  System.exit(0);

                  break;

              default:

                  break;

              }

           } catch (Exception e) {

              System.err.println("请按提示操作!!!");

              normalSuccess(name,power);

           }

          

          

       }

       publicstaticvoid managerSuccess(String name ,int power){

           //管理员登陆成功页面

           System.out.println("=================欢迎进入登录成功页面=================");

           System.out.println("当前用户为:"+name+"\t权限为"+power+"\t0为无权限1为有权限)");

           System.out.println("请按页面提示进行操作:");

           System.out.println("1.查询个人信息");

           System.out.println("2.修改个人信息");

           System.out.println("3.查询全部信息");

           System.out.println("4.按姓名模糊查询");

           System.out.println("5.人工赋权");

           System.out.println("6.修改用户信息");

           System.out.println("7.输入值大于6退出系统");

           Scanner in=new Scanner(System.in); //获取输入权

           try {

              int i=in.nextInt();

              switch (i) {

              case 1:

                  DbService.select(name);

                  break;

              case 2:

                 

                  DbService.alterUser(name);

                  break;

              case 3:

                  DbService.selectAll(name,power);

                  break;

              case 4:

                  DbService.selectByName(name ,power);

                  break;

              case 5:

                  DbService.changePower(name, power);

                  break;

              case 6:                                   

                  DbService.update(name);

                  break;

              case 7:

                  System.exit(0);

                  break;

              default:

                  System.exit(0);

                  break;

              }

           } catch (Exception e) {

              System.err.println("操作非法,强制退出,请按提示操作!!!");

              try {

                  Thread.sleep(500);

              } catch (InterruptedException e1) {

                  e1.printStackTrace();

              }

              Service.login();

           }

          

       }

      

      

      

}

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

JdbcOracle.java

 

 

 

 

package com.zys.Dao;

 

import java.sql.Connection;

import java.sql.DriverManager;

import java.sql.ResultSet;

import java.sql.SQLException;

import java.sql.Statement;

 

public class JdbcOracle {

 

    /**

     * 进行数据库的连接操作

     */

    public static Connection connect() {

       String dirver="oracle.jdbc.driver.OracleDriver";

       String url="jdbc:oracle:thin:@10.1.232.21:1521:ORACLE";

       String user="scott";

       String password="scott";

      

       Connection con=null;

      

 

       //1.添加外部JAR文件,在构建路径-->配置构建路径选项添加Oracle提供的class12.jar文件

       //2.加载驱动程序

       try {

           Class.forName(dirver);

           //System.out.println("驱动加载成功!");

       } catch (ClassNotFoundException e) {

           //System.err.println("加载驱动异常!");

           e.printStackTrace();

       }

       //3.建立数据库连接

       try {

           con=DriverManager.getConnection(url, user, password);

          

       } catch (SQLException e) {

          

           e.printStackTrace();

       }

 

      

       return con;

    }

 

}

 

 

 

 

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值