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

您没有登录

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

按打印兼容模式打印这个话题 打印话题    把这个话题寄给朋友 寄给朋友    该主题的所有更新都将Email到你的邮箱 订阅主题
flat modethreaded modego to previous topicgo to next topicgo to back
作者 请教:连接SQL Server2000时出错
k704790





发贴: 35
积分: 0
于 2004-11-29 21: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
小弟最近写了一个连接MS SQL的测试程序,编译时没有错,可是运行时一行出现错误,不知哪位大哥可以帮一下小弟,代码如下:

package myClass.simon;

//import myClass.simon.*;

import java.sql.*;

/**
*
* @author k704790
*/
public class MyConnectionSQL {

public MyConnectionSQL() {

}

public static void main(String args[]){
//SQLServerConnectionFactory ConnFactory = null;
//JdbcOdbcConnectionFactory ConnFactory = null;
Connection conn = null;
Statement stmt = null;
ResultSet rs = null;
String mySQL = "select job_id,job_desc from dbo.jobs";

System.out.println("这是一个显示SQL数据库连接的例子:");
//ConnFactory = new SQLServerConnectionFactory("localhost",1433,"simon","sa","");
/*try
{
ConnFactory = new SQLServerConnectionFactory("localhost",1433,"simon","sa","sa");
//ConnFactory = new JdbcOdbcConnectionFactory("LocalServer");
ConnFactory.setUserName("sa");
ConnFactory.setPassword("sa");
}
catch(Exception e)
{
System.out.println("初始化出现异常!");
return;
}

System.out.println("DriverName: " + ConnFactory.getDriverName());
System.out.println("URL: " + ConnFactory.getUrl());
System.out.println("UserName: " + ConnFactory.getUserName());
System.out.println("Password: " + ConnFactory.getPassword());
*/

try
{
//conn = ConnFactory.getConnection();
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
}
catch(ClassNotFoundException e)
{
System.out.println("Can't find class");
return;
}

try
{
conn = DriverManager.getConnection("jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=simon;User=sa;Password=sa");
//stmt = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_READ_ONLY);
stmt = conn.createStatement();
rs = stmt.executeQuery(mySQL);
}
catch(SQLException e)
{
System.out.println("Error when return resultset");
return;
}
catch(Exception e)
{
System.out.println("Error:");
e.printStackTrace();
return;
}

try
{
System.out.println("Return resultset: ");
System.out.println("1." + rs.getString("job_desc"));
}
catch(Exception e)
{
System.out.println("显示结果出错!");
}

错误如下:
Error when return resultset


k704790 edited on 2004-12-02 21:31


有了Swing为什么还要SWT?

话题树型展开
人气 标题 作者 字数 发贴时间
6539 请教:连接SQL Server2000时出错 k704790 2711 2004-11-29 21:28
5298 Re:请教:连接SQL Server2000时出错 xhxasdf 271 2004-12-08 14:40
4875 Re:请教:连接SQL Server2000时出错 k704790 3 2005-01-01 22:45

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