Redian新闻
>
How to connect to SQL2000?
avatar
How to connect to SQL2000?# Java - 爪哇娇娃
d*r
1
I tried a whole day but failed.
I used com.microsoft.jdbc.sqlserver.SQLServerDriver.
I can create a connection using DriverManager.getConnection()
But the ResultSet returned by executeQuery() is empty.
avatar
B*N
2
what's your query?

【在 d*r 的大作中提到】
: I tried a whole day but failed.
: I used com.microsoft.jdbc.sqlserver.SQLServerDriver.
: I can create a connection using DriverManager.getConnection()
: But the ResultSet returned by executeQuery() is empty.

avatar
d*r
3

Here is my program:
public class Test {
public Test() {
String sql =
"jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=testdb";
DriverManager.registerDriver(new SQLServerDriver());
Connection conn = DriverManager.createConnection(sql, "sa", "sa");
Statement stmt = conn.createStatement();
String query = "SELECT * FROM mytable";
ResultSet rs = stmt.executeQuery(query);
while (rs.next()) {
int i = rs.getInt("id");


【在 B******N 的大作中提到】
: what's your query?
avatar
B*N
4
first:pay attention that rs.getInt(column_number), the column_number is one
based not zero based.
second:
replace:
DriverManager.registerDriver(new SQLServerDriver());
Connection conn = DriverManager.createConnection(sql, "sa", "sa");
with this:
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
Connection conn = DriverManager.getConnection(sql, "sa", "sa");

【在 d*r 的大作中提到】
:
: Here is my program:
: public class Test {
: public Test() {
: String sql =
: "jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=testdb";
: DriverManager.registerDriver(new SQLServerDriver());
: Connection conn = DriverManager.createConnection(sql, "sa", "sa");
: Statement stmt = conn.createStatement();
: String query = "SELECT * FROM mytable";

avatar
d*r
5
Thank you. Problem solved.
BTW, what's the difference between
DriverManager.registerDriver() and Class.forName()

null.

【在 B******N 的大作中提到】
: first:pay attention that rs.getInt(column_number), the column_number is one
: based not zero based.
: second:
: replace:
: DriverManager.registerDriver(new SQLServerDriver());
: Connection conn = DriverManager.createConnection(sql, "sa", "sa");
: with this:
: Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
: Connection conn = DriverManager.getConnection(sql, "sa", "sa");

相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。