首页 > 数据库技术 > 详细

数据库查询(二)

时间:2017-07-09 13:06:15      阅读:250      评论:0      收藏:0      [点我收藏+]
 1 package com.JDBC.proc;
 2 
 3 import java.sql.*; 
 4 
 5 public class PrepareStatement {
 6     private static final String DBDRIVER = "com.mysql.jdbc.Driver";
 7     private static final String DBURL = "jdbc:mysql://localhost:3306/mldn";
 8     private static final String DBUSER = "root";
 9     private static final String DBPASS = "root";
10     public static void main(String[] args) throws Exception{ 
11         
12         Connection conn=null; 
13         PreparedStatement psmt=null; 
14         ResultSet rs=null; 
15         Class.forName(DBDRIVER);  
16             
17         conn = DriverManager.getConnection(DBURL, DBUSER, DBPASS);
18         String sql="select empno,ename " + "from emp " + "where empno=?"; 
19         psmt=conn.prepareStatement(sql); 
20         psmt.setInt(1, 123); 
21                   
22         rs=psmt.executeQuery(); 
23         while(rs.next()){
24             System.out.println(rs.getInt(1)+"---"+rs.getString(2)); 
25         } 
26         rs.close();
27         psmt.close();
28         conn.close();
29         
30     } 
31 }

 

数据库查询(二)

原文:http://www.cnblogs.com/XuGuobao/p/7141083.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!