- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
当我编译程序时,它生成第一行,该行为空。我认为这是Java中默认的。如何去除它?这是一个MySQL数据库客户端程序,我们可以在其中查看数据库中的数据。但第一行很烦人。
String dbtime;
String query = "Select * FROM EMP";
String[][] celDatas = null;
String[] celNames = null;
try {
// Load the JDBC driver
String driverName = "org.gjt.mm.mysql.Driver"; // MySQL MM JDBC driver
Class.forName(driverName);
// Create a connection to the database
String serverName = "localhost";
String mydatabase = "TestyNaukalne";
String url = "jdbc:mysql://" + serverName + "/" + mydatabase; // a JDBC url
String username = "root";
String password = "";
connection = DriverManager.getConnection(url, username, password);
Statement stmt = connection.createStatement();
ResultSet rs = stmt.executeQuery(query);
ResultSetMetaData rsmd = rs.getMetaData();
int NumOfCol = rsmd.getColumnCount();
rs.last();
int rowCount = rs.getRow();
rs = stmt.executeQuery(query);
celNames = new String[NumOfCol];
celDatas = new String[rowCount+1][NumOfCol];
for(int weq=1; weq<=NumOfCol; weq++) {
System.out.println(rsmd.getColumnName(weq));
celNames[weq-1] = rsmd.getColumnName(weq);
int tmp = 1;
while (rs.next()) {
dbtime = rs.getString(weq);
System.out.println(dbtime);
celDatas[tmp][weq-1] = dbtime;
tmp++;
} //end while
rs = stmt.executeQuery(query);
System.out.println();
}
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
}
final JTable source = new JTable(celDatas,celNames);
JScrollPane pane = new JScrollPane(source);
pane.setSize(f.getSize().width-60,300);
pane.setLocation(30,20);
最佳答案
int tmp = 1; // ******
while (rs.next()) {
dbtime = rs.getString(weq);
System.out.println(dbtime);
celDatas[tmp][weq - 1] = dbtime;
tmp++;
} // end while
数组是基于 0 的,使得数组的 celDatas[0] 行为空。解决方案:不要这样做;将 tmp 初始化为 0。
关于java - JTable 中第一个不必要的空行。如何去除它?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10162071/
jQuery attributeContainsPrefix [name^="value"] 对比 attributeStartsWith [name|="value"] 实际区别是什么? 最佳答案
在1.1部分在RFC 6749中,有四种角色:资源拥有者、资源服务器、客户端和授权服务器。 如果客户端和资源所有者是同一实体,OAuth 是否变得多余或不必要? 例如,我有一个封闭的 API 和一个面
我有一段代码,其中有一个带有保护子句的 raise 语句: def validate_index index # Change to SizeError raise ArgumentError
我看到了这篇文章( JPA Entity Lifecycle Events vs database trigger ),但它并没有像我在这里那样明确地询问: 当我插入 PK 值为 (null) 的行时
所以,我有一段代码看起来像 if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2){ // Do something }
我是一名优秀的程序员,十分优秀!