zoukankan      html  css  js  c++  java
  • 爪哇国新游记之十四----初试JDBC

    import java.sql.Connection;
    import java.sql.DriverManager;
    import java.sql.PreparedStatement;
    import java.sql.ResultSet;
    import java.sql.SQLException;
    
    public class A{
        public static void search1(){
            Connection conn=null;
            PreparedStatement ps=null;
            ResultSet rs=null;
            
            try{
                Class.forName("com.mysql.jdbc.Driver");
                conn=DriverManager.getConnection("jdbc:mysql://127.0.0.1/test", "root", "hy");
                
                String sql=" select * from employee order by salary ";
                ps=conn.prepareStatement(sql);
                rs=ps.executeQuery();            
                
                while(rs.next()){
                    System.out.print(rs.getString("id")+"	");
                    System.out.print(rs.getString("name")+"	");
                    System.out.print(rs.getString("sex")+"	");
                    System.out.print(rs.getInt("salary")+"	");
                    System.out.println();
                }
            }
            catch(SQLException se){
                try{
                    conn.rollback();
                }
                catch(Exception ex){
                    ex.printStackTrace();
                }
            }
            catch(Exception e){
                try{
                    conn.rollback();
                }
                catch(Exception ex){
                    ex.printStackTrace();
                }
            }
            finally{
                try{
                    rs.close();
                    ps.close();
                    conn.close();
                }
                catch(Exception ex){
                    ex.printStackTrace();
                }
            }
        }
    }
  • 相关阅读:
    生成器
    迭代器
    装饰器
    Maven工具学习(六)----Maven依赖的版本锁定与版本常量
    SpringBoot学习记录之整合JSP
    SpringBoot学习记录之入门篇
    【k8s】ep-addresses
    【k8s】ep-metadata
    【k8s】Endpoints
    【k8s】cj-suspend
  • 原文地址:https://www.cnblogs.com/heyang78/p/3867521.html
Copyright © 2011-2022 走看看