zoukankan      html  css  js  c++  java
  • JDBC 查询

    //查询""SMITH"的empno
    import java.sql.Connection;
    import java.sql.DriverManager;
    import java.sql.PreparedStatement;
    import java.sql.ResultSet;
    import java.sql.SQLException;
    
    
    
    public class TestJdbc2 {
        public static void main(String[] args) throws ClassNotFoundException, SQLException {
            //1.加载数据库驱动类
            Class.forName("oracle.jdbc.OracleDriver");
            //2.获取数据库连接对象
            String url = "jdbc:oracle:thin:@127.0.0.1:1521:orcl";
            String user = "SCOTT";
            String password = "tiger";        
            
            Connection connection = DriverManager.getConnection(url, user, password);
            
            //3.创建sql字符串
            String sql = "select * from emp where ename = ?";
            //4.创建preparedStatement对象
            PreparedStatement pS = connection.prepareStatement(sql);
            //5.获取结果集
            pS.setString(1, "SMITH");
            ResultSet rs = pS.executeQuery();
            //6.遍历
            while(rs.next()){
                System.out.println(rs.getInt("empno"));
            }
            //7.释放资源
            rs.close();
            pS.close();
            connection.close();
        }
    }
  • 相关阅读:
    ShiroConfig V2.0
    MyRealm V2.0(注:加上了权限字符串)
    ShiroUtils通用工具包
    ResourcesConfig实现配置资源路径
    MyRealm V1.0
    ShiroConfig V1.0
    MySQL
    Git实战
    scala中函数简单使用记录
    scala中Trait简单使用
  • 原文地址:https://www.cnblogs.com/heviny/p/10752098.html
Copyright © 2011-2022 走看看