如何连接远程SQL Server数据库? [英] How to connect remote sql server database?
问题描述
我创建了一个远程SQL Server 2005数据库。
我需要从它那里得到一些数据。我怎样才能做到这一点?
如果你给我的code我会很高兴,并告诉我,我需要插入每一件事情(如用户名,密码,断绝等)
谢谢你,有一个美好的一天!
罗恩
I have created a remote sql server 2005 database.
I need to get some data from it. How can I do this?
I would be glad if you gave me the code and tell me where I need to insert each thing (like username, password, sever etc.)
Thank you and have a good day!
Ron
推荐答案
我建议你使用的标准库中的java.sql包。类DriverManager应该有你需要的东西。连接可能看起来像这样的例子(取决于你用什么驱动程序 - 与你需要的驱动程序替换com.mysql.jdbc.Driver):
I suggest you use the features of the standard library in the package java.sql. The DriverManager should have what you need. An example of a connection could look something like this (depending on what driver you use - replace the "com.mysql.jdbc.Driver" with the driver you need):
Class.forName("com.mysql.jdbc.Driver").newInstance();
Connection connection = DriverManager.getConnection(
"jdbc:mysql://insert_address_here/",
"user","password");
Statement statement = connection.createStatement();
ResultSet result = statement.executeQuery(
"SELECT * FROM sometable WHERE id = 1");
..只是作为一个例子。请参阅 java2s 更多的例子。特别是在的DriverManager 和[ResultSet中的 4 。
.. Just as an example. See more examples in java2s. Particularly under DriverManager and [ResultSet4.
这篇关于如何连接远程SQL Server数据库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!