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

您没有登录

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

按打印兼容模式打印这个话题 打印话题    把这个话题寄给朋友 寄给朋友    该主题的所有更新都将Email到你的邮箱 订阅主题
flat modethreaded modego to previous topicgo to next topicgo to back
作者 sql server 2000 jdbc driver访问sql server2000出错
taxi



发贴: 0
积分: 0
于 2003-11-26 21:29 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
代码如下:
import java.sql.*;

public class PrintEmployees
{
public static void main(String[] args)
{
String driverName = "com.microsoft.jdbc.sqlserver.SQLServerDriver";
String connURL = "jdbc:microsoft:sqlserver://taxi:1433;User=sa;Password=;DatabaseName=Northwind";

try
{
Class.forName(driverName);
Connection conn = DriverManager.getConnection(connURL);
PreparedStatement stmt = conn.prepareStatement("SELECT FirstName, LastName, BirthDate FROM Employees");
ResultSet rs = stmt.executeQuery();

while (rs.next());
{
System.out.println("FirstName:" + rs.getString(1));
System.out.println(" LastName:" + rs.getString(2));
System.out.println("BirthDate:" + rs.getDate(3));
System.out.println("");
}

rs.close();
stmt.close();
conn.close();
}
catch (ClassNotFoundException ex)
{
ex.printStackTrace();
}
catch (SQLException ex)
{
ex.printStackTrace();
}
}
}

错误信息如下:
java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC]Invalid operation for the current cursor position.
at com.microsoft.jdbc.base.BaseExceptions.createException(Unknown Source)
at com.microsoft.jdbc.base.BaseExceptions.getException(Unknown Source)
at com.microsoft.jdbc.base.BaseResultSet.validateCursorPosition(Unknown Source)
at com.microsoft.jdbc.base.BaseResultSet.getString(Unknown Source)
at PrintEmployees.main(PrintEmployees.java:19)

第19行的代码为:System.out.println("FirstName:" + rs.getString(1));

请问是什么原因?



作者 Re:sql server 2000 jdbc driver访问sql server2000出错 [Re:taxi]
ejb





发贴: 33
积分: 20
于 2003-11-26 22:17 user profilesend a private message to usersend email to ejbsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
>>while (rs.next());

多了个分号吧?



作者 Re:sql server 2000 jdbc driver访问sql server2000出错 [Re:taxi]
taxi



发贴: 0
积分: 0
于 2003-11-27 09:08 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
哦,谢谢。
原来是这个小错误。





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