Use JDBC to connect MS SQL Server 2000 + SP2

xiaoxiao2021-03-06  74

When I learned J2EE, I used JDBC to connect to MS SQL Server 2000. Everything was normal, but later I met a very headache, that is, we read the data from the table to the ResultSet, read columns When the value is read in the order of the column, for example, if there are three ids, name, address, the result obtained by the condition query is placed in the ResultSet, and if this is written when the result is displayed.

Java.sql.resultset Employees; while (Employees.Next ()) {Employees.getstring ("address"); Employees.getstring ("name");} will "Column Can Not Be Re-Read" when running Error, it is good to reverse the two statements (this article only applies to connect MS SQL Server 2000)

The connection database 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 ); CatchNotfoundExcection E) {system.err.println (e);}

转载请注明原文地址:https://www.9cbs.com/read-108255.html

New Post(0)