数据库结果没有在java中显示

时间:2016-02-21 05:02:27

标签: java jdbc

我输入了这段代码,但没有记录来自数据库...我已经附加了Ms Access数据库 需要帮助... 输出只表示"建立成功"。

import java.sql.*;

public class Db {

    Connection con;
    Statement st;
    ResultSet rs;

   //constructor
    public Db(){

        connect();
    }

    //connect funtion
    public void connect(){

        try {
            String driver;
            driver = "sun.jdbc.odbc.JbdcObdcDriver";
            Class.forName(driver);

            String db;
            db="jbdc:obdc:db2";
           //connectin to db 
            con=DriverManager.getConnection(db);


            String sql;
            sql="Select * from Table1";

            rs=st.executeQuery(sql);


            while (rs.next()){

                String fname=rs.getString("FirstName");

                String lname=rs.getString("LastName");

                String age=rs.getString("age");

                System.out.println(fname+" "+lname+" "+age);
            }
        } catch (Exception e) {
            System.out.println(e.getMessage());
        }
    }

    public static void main(String[] args) {
        // TODO code application logic here
    }
          Db d=new Db();

0 个答案:

没有答案