jdbc中数据库查询我的那个方法更好?有更好的办法吗?求大神指点

/*

  • 查询数据库表t1中的数据
    /
    public void select() {
    //连接数据库
    getDBCconnect();
    try {
    //sql语句
    String sql="select * from t1 where id=1";
    //创建要执行sql语句的对象
    sta= con.createStatement();
    //执行sql语句并将得到的结果放到结果集中
    ResultSet result= sta.executeQuery(sql);
    //
    *方法一:**

    //处理结果集的对象
    ResultSetMetaData mtd= result.getMetaData();
    while(result.next()){

            //总列数
            int size=mtd.getColumnCount();
            for(int z=1;z<=size;z++){
                //输出所有结果
                System.out.print(result.getString(z)+"\t");
            }
        }
    

    //**方法二:****

    // while(result.next()){//如果有下一行
    // int id=result.getInt("id");
    // String name=result.getString("name");
    // int age=result.getInt("age");
    // String adress=result.getString("adress");
    // System.out.println("编号:"+id+" 姓名:"+name+" 年龄:"+age+" 地址:"+adress);
    // }
    } catch (SQLException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }

    }

这以后都整合到springmvc中了,反正我是不写jdbc工具类

ok,谢谢!兴趣而已 喜欢过程