这个问题在这里已经有答案了:
如何用java打印信息表(4个答案)
上个月关门了。
我需要把数据库的输出打印成一个表
public static void main(String[] args) {
try
{
Class.forName("com.mysql.jdbc.Driver");
Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/walmart?characterEncoding=utf8","root","toor");
Statement stmt=con.createStatement();
ResultSet rs=stmt.executeQuery("select * from salesperson");
System.out.println(" Employee ID "+" Employee Name "+" Contact "+" Region "+"Sales");
while(rs.next())
System.out.println(rs.getInt(1)+" "+rs.getString(2)+" "+rs.getInt(3)+" "+rs.getString(4)+" "+rs.getFloat(5));
//step5 close the connection object
con.close();
}
catch(Exception e){ System.out.println(e);}
} }
1条答案
按热度按时间mitkmikd1#
这是未经测试的快速方法code:-