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

您没有登录

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

按打印兼容模式打印这个话题 打印话题    把这个话题寄给朋友 寄给朋友    该主题的所有更新都将Email到你的邮箱 订阅主题
flat modethreaded modego to previous topicgo to next topicgo to back
作者 各位哥哥姐姐帮个忙啦!!(关于JDBC)
193kuanglv





发贴: 6
积分: 0
于 2006-04-06 08:54 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
快一个星期了 我真的搞不通啊!!!
就是连不上SQL SERVER

import java.util.*;
import java.sql.*;

public class TestDB
{
public static void main(String[] args)
{
try {
runTest();
}
catch (SQLException ex) {
while (ex != null)
{
ex.printStackTrace();
ex.getNextException();
}
}
}
public static void runTest() throws SQLException
{
Connection con = TestDB.getConnection();
try
{
Statement state = con.createStatement();

state.execute("CREATE TABLE Greetings (Message CHAR(20))");
state.execute("INSERT INTO Greetings VALUES ('hello world!')");

ResultSet result = state.executeQuery("SELECT * FROM Greetings");
result.next();
System.out.print(result.getString(1));
//state.execute("DROP TABLE Greetings");
}
finally
{
con.close();
}
}
public static Connection getConnection() throws SQLException
{
String drivers = "com.microsoft.jdbc.sqlserver.SQLServerDriver";
System.setProperty("jdbc.drivers", drivers);
String url = "jdbc:microsoft:sqlserver://192.168.0.3:1433;databasename=COREJAVA";
String username = "sa";
String password = "awdz123";

return DriverManager.getConnection(url,username,password);
}
}
使用系统版本: windows 2003 server enterprise edition
使用编译工具: JBuilder 2006
使用数据库版本 SQL Server 2000
连接时出现的异常:
java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC]Error establishing socket.
  at com.microsoft.jdbc.base.BaseExceptions.createException(Unknown Source)
  at com.microsoft.jdbc.base.BaseExceptions.getException(Unknown Source)
  at com.microsoft.jdbc.base.BaseExceptions.getException(Unknown Source)
  at com.microsoft.jdbc.sqlserver.tds.TDSConnection.<init>(Unknown Source)
  at com.microsoft.jdbc.sqlserver.SQLServerImplConnection.open(Unknown Source)
  at com.microsoft.jdbc.base.BaseConnection.getNewImplConnection(Unknown Source)
  at com.microsoft.jdbc.base.BaseConnection.open(Unknown Source)
  at com.microsoft.jdbc.base.BaseDriver.connect(Unknown Source)
  at java.sql.DriverManager.getConnection(DriverManager.java:525)
  at java.sql.DriverManager.getConnection(DriverManager.java:171)
  at testdb.TestDB.getConnection(TestDB.java:49)
  at testdb.TestDB.runTest(TestDB.java:23)
  at testdb.TestDB.main(TestDB.java:11)
java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC]Error establishing socket.
  at com.microsoft.jdbc.base.BaseExceptions.createException(Unknown Source)
  at com.microsoft.jdbc.base.BaseExceptions.getException(Unknown Source)
  at com.microsoft.jdbc.base.BaseExceptions.getException(Unknown Source)
  at com.microsoft.jdbc.sqlserver.tds.TDSConnection.<init>(Unknown Source)
  at com.microsoft.jdbc.sqlserver.SQLServerImplConnection.open(Unknown Source)
  at com.microsoft.jdbc.base.BaseConnection.getNewImplConnection(Unknown Source)
  at com.microsoft.jdbc.base.BaseConnection.open(Unknown Source)
环境变量已设置,也将3个.jar文件拷到目标文件夹了,SQL Server 使用Ado.net 连接时没有问题。
一开始以为各软件有问题,全部重新安装(包括系统),搞了一个礼拜,快崩溃了!!!
求你们了,一定得帮个忙, 因为这个问题每天吃不好,睡不着,
请帮我一下,一定,请帮我!!! QQ357037014




话题树型展开
人气 标题 作者 字数 发贴时间
10463 各位哥哥姐姐帮个忙啦!!(关于JDBC) 193kuanglv 3313 2006-04-06 08:54
8394 Re:各位哥哥姐姐帮个忙啦!!(关于JDBC) Jcat 68 2006-04-06 14:03
9197 Re:各位哥哥姐姐帮个忙啦!!(关于JDBC) java8964 1063 2006-04-12 01:22

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