Java开发网 Java开发网
注册 | 登录 | 帮助 | 搜索 | 排行榜 | 发帖统计  

您没有登录

» Java开发网 » Database/JDBC/SQL/JDO/Hibernate  

按打印兼容模式打印这个话题 打印话题    把这个话题寄给朋友 寄给朋友    该主题的所有更新都将Email到你的邮箱 订阅主题
flat modethreaded modego to previous topicgo to next topicgo to back
作者 [求助]关于getTableName返回""
RockWang





发贴: 5
积分: 0
于 2006-03-29 17:52 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
小弟近日在做一个项目,JAVA挂SQL的一个MIS
在写UPDATE语句的时候遇到了困难,就是不论怎么样,getTableName返回的全是"".(注意,不是空值,下面我验证过了)
(getTableName是java.sql.ResultSetMetaData的方法)
public abstract String getTableName(int column) throws SQLException

其他的方法,比如getColumnName(int) ,getColumnLabel(int) 都可以正确的取得我想要的值.唯有getTableName是死活不行啊~~~郁闷~~~

请各位高手帮我解决下,谢鸟~~~

另:我的开发环境
JCreator 3.50 Pro
Microsoft SQL Server 2000 SP4
Microsoft SQL Server 2000 Driver for JDBC SP3

连接语句:
public static Connection getConnection() throws SQLException {
String url = "jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=northwind";
try {
Class.forName(("com.microsoft.jdbc.sqlserver.SQLServerDriver"));
} catch (ClassNotFoundException ex) {
ex.printStackTrace();
return null;
}
return DriverManager.getConnection(url,"sa","");
}

声明:
ResultSetMetaData metaData;

赋值:
String tableName = metaData.getTableName(column+1);

""验证得到的结果......
if (tableName == "") {
System.out.println("Table name returned null.");
}
每次都很给面子的输出Table name returned null.

null验证得到的结果......
if (tableName == null) {
System.out.println("Table name returned null.");
}
这个就死活不给我面子了,""和null是不是不一样啊.


RockWang edited on 2006-03-29 18:01

作者 Re:[求助]关于getTableName返回"" [Re:RockWang]
RockWang





发贴: 5
积分: 0
于 2006-03-31 08:35 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
- -
试了好几种方法了,还是不能取得结果的说......高手来啊



作者 Re:[求助]关于getTableName返回"" [Re:RockWang]
zcjl

涅槃



发贴: 537
积分: 65
于 2006-03-31 09:28 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
也许是jdbc驱动的问题?
我使用MySQL4.1.0 with mysql-connector-java-3.0.10-stable-bin就可以正确取得tableName



作者 Re:[求助]关于getTableName返回"" [Re:RockWang]
RockWang





发贴: 5
积分: 0
于 2006-03-31 09:55 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
也许真的是M$的驱动不支持tableName?
那么还有问题,挂SQL的话JDBC ODBC的桥接好还是jTDS更好呢?



作者 Re:[求助]关于getTableName返回"" [Re:RockWang]
zcjl

涅槃



发贴: 537
积分: 65
于 2006-03-31 10:19 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
还是使用jtds吧,对ms sql的支持很不错的
当然,也有付费版的ms sql jdbc驱动



作者 Re:[求助]关于getTableName返回"" [Re:RockWang]
RockWang





发贴: 5
积分: 0
于 2006-03-31 15:42 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
郁闷,jTDS同样无法取得表名.......开始怀疑是不是自己的语句有问题了.......


作者 Re:[求助]关于getTableName返回"" [Re:RockWang]
zcjl

涅槃



发贴: 537
积分: 65
于 2006-03-31 16:22 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
public void testGetTableName() throws SQLException {
Connection conn = getConnection();
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery("select * from table1");
ResultSetMetaData rsmd = rs.getMetaData();
String tName = rsmd.getTableName(1);
System.out.println(tName);
//close()...
}



作者 Re:[求助]关于getTableName返回"" [Re:RockWang]
RockWang





发贴: 5
积分: 0
于 2006-04-01 21:31 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
还是不成.郁闷了郁闷了,不过还是谢谢zcjl 兄的帮助,我换个方法实现好了



flat modethreaded modego to previous topicgo to next topicgo to back
  已读帖子
  新的帖子
  被删除的帖子
Jump to the top of page

   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923