Connect ms SQL Ser2000 + sp2 using JDBC

Source: Internet
Author: User

When I was learning j2ee, I used jdbc to connect to ms SQL server 2000. At the beginning, everything was normal, but then I encountered a headache, after we read data from the table and put it in the ResultSet, we must read the column values in the column order.
For example, if the table contains three columns: id, name, address, and the result obtained by the conditional query is placed in the ResultSet. If the result is displayed, write the code as follows:
Java. SQL. ResultSet employees;
While (employees. next ()){
Employees. getString ("address ");
Employees. getString ("name ");
}
When running, the "column can not be re-read" error will occur. In this case, the two statements will be reversed (this is only applicable to connecting ms SQL Server 2000)
The database connection code is as follows:
Try {
Class. forName ("com. microsoft. jdbc. sqlserver. SQLServerDriver ");
Conn =
DriverManager. getConnection (
"Jdbc: microsoft: sqlserver: // localhost: 1433; DatabaseName = Hotel; User = sa; Password = sa ");
// Class. forName ("sun. jdbc. odbc. JdbcOdbcDriver ");
// Conn = DriverManager. getConnection ("jdbc: odbc: hotel ");
} Catch (SQLException e ){
System. err. println (e );
} Catch (ClassNotFoundException e ){
System. err. println (e );
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.