System.out.println()从数据库变成表 [英] System.out.println() from database into a table

查看:198
本文介绍了System.out.println()从数据库变成表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前,我将数据从MS Access数据库和java应用程序I system.out.print中提取到控制台。我使用/ t来分隔数据,但它显得很笨拙。我想将它放在某种桌子上以获得更令人愉悦的外观。任何帮助都会非常感谢。

At present I pull my data from an MS Access database and within a java application I system.out.print it to the console. I used /t to space out the data, however it appears awkwardly. I would like to place it in some kind of table for a more pleasing look. Any help would be great thanks.

          while(rs.next())
      {
          System.out.print(rs.getInt("season_number")+"\t");
          System.out.print(rs.getInt("season_episode_number")+"\t");
          System.out.print(rs.getInt("series_episode_number")+"\t");
          System.out.print(rs.getString("title")+"\t");
          System.out.print(rs.getString("directed_by")+"\t");
          System.out.print(rs.getString("written_by")+"\t");
          System.out.print(rs.getDate("origional_air_date")+"\t");
          System.out.println(rs.getFloat("viewing_figures")+"\t");

      }
   }


推荐答案

为了理顺你的输出,最佳解决方案是使用 System.out.printf()

The best solution in order to straighten your output out will be to use System.out.printf().

由于printf与C'printf非常相似,因此您可以使用控制字符来格式化输出。像这样:

Since printf is very similar to C' printf, you can use control characters in order to format the output. Like this:

System.out.printf( "%-3.2d %-20.20s\n", rs.getInt("season_number"), rs.getString("title") );

检查链接

这篇关于System.out.println()从数据库变成表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆