• myeclise连接oracle数据库实现登录


    package A;

    import java.sql.Connection;
    import java.sql.DriverManager;
    import java.sql.PreparedStatement;
    import java.sql.ResultSet;
    import java.sql.SQLException;
    import java.util.Scanner;

    public class My_ORCLE {
        
        public static void main(String[] args) {
            String classname="oracle.jdbc.driver.OracleDriver";
            String url="jdbc:oracle:thin:@localhost:1521:orcl";
            String user="epet";
            String pwd="123";
            
            
            Connection con=null;
            PreparedStatement pre=null;
            ResultSet rs=null;
            
            try {
                //实例化键盘输入对象
                Scanner input=new Scanner(System.in);
                
                System.out.print("请输入用户名:");
                String username=input.next();
                
                System.out.print("请输入密码:");
                String password=input.next();
                
                //加载驱动
                Class.forName(classname);
                
                //创建连接
                con=DriverManager.getConnection(url,user,pwd);
                
                //编写Sql语句
                String sql="select * from master where loginid=? and password=?";
                
                pre=con.prepareStatement(sql);
                pre.setString(1,username);
                pre.setString(2,password);
                
                //得到结果集
                rs=pre.executeQuery();
                
                if(rs.next()){
                    System.out.println("欢迎您:"+username);
                }else{
                    System.out.println("登录失败!!");
                }
                
                
            } catch (ClassNotFoundException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (SQLException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }finally{
                //释放内存
                
                    try {
                        if(rs !=null){
                        rs.close();
                         }
                        if(pre !=null){
                            pre.close();
                           }
                        if(con !=null){
                            con.close();
                           }
                        
                        
                    } catch (SQLException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    
                }
                
            }

        }

    }

  • 相关阅读:
    什么是索引?怎么创建索引?索引的使用原则?
    Cookie和Session的区别
    HashMap、Hashtable、ConcurrentHashMap的原理与区别
    vxlogcfg vxlogcfg – 修改统一日志记录配置设置
    磁盘阵列RAID介绍及计算公式
    二叉树的最近公共祖先 递归
    LRU 缓存机制
    从前序与中序遍历序列构造二叉树 递归
    MySQL 数据结构常用命令
    Node.Js 搭建简单的 EggJs 示例项目
  • 原文地址:https://www.cnblogs.com/ziyasi/p/4482660.html
Copyright © 2020-2023  润新知