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

您没有登录

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

按打印兼容模式打印这个话题 打印话题    把这个话题寄给朋友 寄给朋友    该主题的所有更新都将Email到你的邮箱 订阅主题
flat modethreaded modego to previous topicgo to next topicgo to back
作者 用java怎么进行远程数据库连接阿?
爱猫的青蛙





发贴: 18
积分: 0
于 2006-06-12 11: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
String url="jdbc:odbc:Ac_check";

Class.forName( "sun.jdbc.odbc.JdbcOdbcDriver" );

Connection con=DriverManager.getConnection(url,user,password);

这上面是在本机进行数据库连接
请问如果在别的机子上想访问数据库
这个url该如何书写呢?

还有数据库需要做什么设置么?
我用的是sql 2000

我看到很多资料上写的是
url=jdbc:odbc:+sDsn\Ac_check

我不太明白这个sDsn是怎么用

比如装有数据库的机子ip为202.186.1.1
该如何写进去呢?

还有加载那个驱动程序的部分classforname需要改写么?

谢谢大家



作者 Re:用java怎么进行远程数据库连接阿? [Re:爱猫的青蛙]
why

問題兒童

总版主


发贴: 4629
积分: 388
于 2006-06-12 21:19 user profilesend a private message to usersend email to whysearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
1. Search for DSN

2. You could use a JDBC driver instead of this ODBC-JDBC bridge.
Almost every topic about SQL Server has information about this.



作者 Re:用java怎么进行远程数据库连接阿? [Re:爱猫的青蛙]
爱猫的青蛙





发贴: 18
积分: 0
于 2006-06-13 09:02 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
谢谢why

你已经帮过我好几次了



作者 Re:用java怎么进行远程数据库连接阿? [Re:爱猫的青蛙]
why

問題兒童

总版主


发贴: 4629
积分: 388
于 2006-06-13 09:53 user profilesend a private message to usersend email to whysearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
爱猫的青蛙 wrote:
谢谢why

你已经帮过我好几次了

My pleasure.
Just let us know if you need more help.



Class.forName( "com.microsoft.jdbc.sqlserver.SQLServerDriver" );/*加载指定的驱动程序*/

String url="jdbc:microsoft:sqlserver://IP:1433;Ac_check";

这个样子我还是找不到驱动程序
为什么呢
然后我在前面加上了

import com.microsoft.jdbc.*;后
编译报错
说:软件包com.microsoft.jdbc不存在

但是我已经将我下到的mssqlserver.jar,msbase.jar,msutil.jar装到了jdk\lib\下面啊

为什么不行呢?

I guess it should be jdk\lib\ext
I am not sure and am lazy to double-check, since I would rather put the jars on the classpath in a batch file.

I don't think you have to import com.microsoft.jdbc.*;

If the name of your database is Ac_check, the connection string would be
jdbc:microsoft:sqlserver://<YOUR_IP>:1433;databasename=Ac_check;


why edited on 2006-06-13 10:42

作者 Re:用java怎么进行远程数据库连接阿? [Re:爱猫的青蛙]
爱猫的青蛙





发贴: 18
积分: 0
于 2006-06-13 15: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
我把环境变量
改成了classpath=D:\Java\jdk1.6.0\lib\dt.jar;D:\Java\jdk1.6.0\lib\htmlconverter.jar;D:\Java\jdk1.6.0\lib\tools.jar;D:\Java\jdk1.6.0\lib\jconsole.jar;D:\Java\jdk1
.6.0\lib\msbase.jar;D:\Java\jdk1.6.0\lib\mssqlserver.jar;D:\Java\jdk1.6.0\lib\
msutil.jar;D:\Java\jdk1.6.0\bin;

但是运行的时候还是找不到驱动程序
是为什么呢?



作者 Re:用java怎么进行远程数据库连接阿? [Re:爱猫的青蛙]
爱猫的青蛙





发贴: 18
积分: 0
于 2006-06-13 20: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
我发现我classpath写错了

然后后来运行出现error establishing socket

发现在局域网内如果直接写ip地址的话一定要到网关作端口映射
不能直接写ip
如果是公网,就可以直接写ip地质
在局域网内如果不想做端口映射就得直接写服务器名字




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