标签:style blog java color os io for re
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")+"\t"); System.out.print(rs.getString("name")+"\t"); System.out.print(rs.getString("sex")+"\t"); System.out.print(rs.getInt("salary")+"\t"); 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(); } } } }
爪哇国新游记之十四----初试JDBC,布布扣,bubuko.com
标签:style blog java color os io for re
原文地址:http://www.cnblogs.com/xiandedanteng/p/3867521.html