使用j-text utils的TextTable类而不是带有ResultSet值的表打印Resultset时获取异常

时间:2017-10-09 18:02:30

标签: java jdbc resultset

尝试使用以下代码从java中的ResultSet打印表但收到错误:

Exception in thread "main" java.lang.NoClassDefFoundError: 
org/apache/commons/lang/StringUtils
at dnl.utils.text.table.TextTableRenderer.render(TextTableRenderer.java:42)
at dnl.utils.text.table.TextTable.printTable(TextTable.java:76)
at dnl.utils.text.table.TextTable.printTable(TextTable.java:71)
at autopack.JDBC_Connection.main(JDBC_Connection.java:146)
Caused by: java.lang.ClassNotFoundException: 
org.apache.commons.lang.StringUtils
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
... 4 more

代码:

for ( int i = 0,j=1; j <= columnsNumber; i++,j++ ) 
{
    ColumnNames[i]=rsmd.getColumnLabel(j);
}
rs.last();
int RowCount=rs.getRow();
rs.beforeFirst();

Object[][] data = new Object[RowCount][columnsNumber];
int i=0;

while(rs.next())
{
for (int j=0; j+1<=columnsNumber; j++) 
{
data[i][j] = rs.getString(j+1);
}
i++;
}

TextTable tt = new TextTable(ColumnNames, data);
tt.setAddRowNumbering(true);
tt.printTable();

注意:添加SOP以打印Pass以检查代码失败或未到达的位置。 从以下代码获得上述代码示例:Write j-text utils table to file

0 个答案:

没有答案