zqmcomputer

统计

积分与排名

最新评论

java连接数据库

 import  java.sql.*;

public class testJdbc

{   public static void main(String[] args)

                { try

                       {Class.forName("Sun.jdbc.odbc.JdbcOdbcDriver");

                          String Source="jdbc:odbc:myAccess";
                          Connection con=DriverManger.getConnetion(source);
                           Statement stmt=con.createStatement();
                           String sql="select * from user";

                           ResultSet rs=stmt.executeQuery(sql);
                           String id, name, pwd;
                  while(rs.next())
                           {
                                 id=rs.getString(1);
                                 name=rs.getString(2);
                                 pwd=rs.getString(3);
                                  System.out.println(id+","+name+","+pwd);


                            }
       rs.close();
       stmt.close();
       con.close();
              }

}

posted on 2008-04-12 16:06 风林芝 阅读(217) 评论(0)  编辑 收藏 引用 所属分类: 学习区

只有注册用户登录后才能发表评论。