Chinaunix首页 | 论坛 | 博客

-

  • 博客访问: 162787
  • 博文数量: 48
  • 博客积分: 2000
  • 博客等级: 大尉
  • 技术积分: 490
  • 用 户 组: 普通用户
  • 注册时间: 2009-04-22 18:51
文章分类

全部博文(48)

文章存档

2010年(23)

2009年(25)

我的朋友

分类: Java

2009-10-27 14:34:56

package com.access.database;
import java.sql.*;
public class JDBCAc {
 public static void main(String[] args) {
  try{
   Class.forName("com.mysql.jdbc.Driver");
  }catch(ClassNotFoundException e){
   e.printStackTrace();
  }
  Connection con=null;
  PreparedStatement stmt=null;
  ResultSet rs=null;
  try{
   con=DriverManager.getConnection("jdbc:mysql://localhost:3306/xjgl", "root", "zxs");
   stmt=con.prepareStatement("select * from xjgl_xsb where xsxb=?");
   stmt.setString(1, "男");
   rs=stmt.executeQuery();
   while(rs.next()){
    System.out.println(rs.getString(1)+"  "+rs.getString(2)+"  "+rs.getString(3)+"   "+rs.getString(4)+"   "+rs.getString(5));
   }
  }catch(SQLException e){
   e.printStackTrace();
  }finally{
   try {
    rs.close();
    stmt.close();
    con.close();
   } catch (SQLException e) {
    e.printStackTrace();
   }
  }
 }
}
阅读(1219) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~