java代码测试
版权声明:原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 、作者信息和本声明。否则将追究法律责任。http://zzzkkk666.blog.51cto.com/308274/87508 |
import java.sql.*; public class dbtest{ public static void main(String[] args) throws Exception { int i=0; String url = "jdbc:oracle:thin:@127.0.0.1:1521:orcl"; Class.forName("oracle.jdbc.OracleDriver"); Connection conn = DriverManager.getConnection(url, "tt", "tt"); ResultSet rs = null; PreparedStatement pstmt = null; String sql = "SELECT * FROM PERSON"; //String sql = "SELECT * FROM PERSON where id ='lxh'"; try{ pstmt = conn.prepareStatement(sql); //pstmt.setString(1, "lxh");//设置上边第一个问号里填的值 rs = pstmt.executeQuery(); while(rs.next()) { i++; System.out.println("第"+i+"行数据"); System.out.print(rs.getString("id")+" "); System.out.print(rs.getString("name")+" "); System.out.print(rs.getString("password")+" "); System.out.print("\n"); } } finally{ if(rs != null){ try{rs.close();}catch(SQLException e){} } if(pstmt != null){ try{pstmt.close();}catch(SQLException e){} } if(conn != null){ try{conn.close();}catch(SQLException e){} } } } } 本文出自 “zzzkkk666” 博客,请务必保留此出处http://zzzkkk666.blog.51cto.com/308274/87508 本文出自 51CTO.COM技术博客 |


zzzkkk666
博客统计信息
热门文章
最新评论
友情链接
