没有getTableName()方法吧
只有getTables(),表名在返回的ResultSet中
只有getTables(),表名在返回的ResultSet中
解决方案 »
- 英雄会之在线笔试面试,等你来挑战(更新至2013/5/22)
- 求教:如何用Java生成下面内容的XML文件?求源码~
- 求一SQL
- 帮我解答一下吧
- 关于接口的问题?急用。
- Think in java 的一个例题,有些不明白,望高手指教。。。
- 这种东西到底是什么?
- JAVA中常用的那些类,如java.lang,javax.swing都存放在哪个目录?我怎么找不到阿。
- 怎样把面板上的各种控件和用paint画的图象保存为图象格式(jpg,jpeg,bmp)都可以(谢谢)
- 请教,jdbc的连接串中怎么带上sqlserver的实例名称?(急死我了)
- so奇怪,9*0.1f的问题。
- 向一个DefaultTableModel插入一行数据为何失败???
throws SQLExceptionGets the designated column's table name. Parameters:
column - the first column is 1, the second is 2, ...
Returns:
table name or "" if not applicable
Throws:
SQLException - if a database access error occurs但是我就不知道为什么每次都是"",而无法取得table name!!!!
String[] table_type={"TABLE"};
ResultSet result=dmd.getTables(null,null,null,table_type);
Vector tableNames=new Vector();
while(result.next()){
tableNames.add(result.getString("TABLE_NAME"));
}
int pos=sql.toLowerCase().indexOf("from");
if (pos>0){
String t=sql.toLowerCase().substring(pos+4).trim();
pos=t.indexOf(" ");
if (pos>0)
return t.substring(0,pos).trim();
else
return t;
}else
return "";
}凑合着用吧
public String getTableName(int column)
throws SQLExceptionGets the designated column's table name. Parameters:
column - the first column is 1, the second is 2, ...
Returns:
table name or "" if not applicable
Throws:
SQLException - if a database access error occursJDK1.4下面DEMO中有一例子TableExamples中就有 JDBCAdapter ,里面也用到了
public void setValueAt(Object value, int row, int column) {
try {
String tableName = metaData.getTableName(column+1);
// Some of the drivers seem buggy, tableName should not be null.
if (tableName == null) {
System.out.println("Table name returned null.");
}
String columnName = getColumnName(column);
String query =
"update "+tableName+
" set "+columnName+" = "+dbRepresentation(column, value)+
" where ";
// We don't have a model of the schema so we don't know the
// primary keys or which columns to lock on. To demonstrate
// that editing is possible, we'll just lock on everything.
for(int col = 0; col<getColumnCount(); col++) {
String colName = getColumnName(col);
if (colName.equals("")) {
continue;
}
if (col != 0) {
query = query + " and ";
}
query = query + colName +" = "+
dbRepresentation(col, getValueAt(row, col));
}
System.out.println(query);
System.out.println("Not sending update to database");
// statement.executeQuery(query);
}
catch (SQLException e) {
// e.printStackTrace();
System.err.println("Update failed");
}
Vector dataRow = (Vector)rows.elementAt(row);
dataRow.setElementAt(value, column); }上面代码第三行,就是我所说的语句
因为上面也提到了:
// Some of the drivers seem buggy, tableName should not be null.
所以charbee(char) 说得对,可以是drivers有问题,但我不知道如何解决啊
ODBC-JDBC、JDBC我都用过了,得到的都是""