Get the App
SLTechnology News&Howtos  ›  Development  › 

How to solve the resultset defect of Microsoft's own JDBC

Shulou Source: shulou.com Published: 2022-06-02 07:32:28 11月15日 Update

This article introduces how to solve the resultset defect of Microsoft's own JDBC, the content is very detailed, interested friends can refer to, hope to be helpful to you.

Microsoft comes with three driver packages: msbase.jar,mssqlserver.jar,msutil.jar

The disadvantages of Microsoft's JDBC resultset driver:

(1) if the jdbc-odbc driver is used, it must be read once according to the query order (with or without image or text type)

(2) if you use the ms sql server jdbc driver provided by Microsoft, if there is no image or text type field in the query statement, you can get it out of order.

(3) if you use ms sql server jdbc driver provided by Microsoft, if there are fields of type image or text in the query statement, you must read them in order, otherwise errors such as Driver] ResultSet can not re-read row data for column will be reported.

The test method and code are as follows:

Database table: TestTable

Table fields and types:

Guid char (38)

Title varchar (100)

Content Text

Username varchar (20)

JDBC resultset code

Public static void main (String [] args) {/ / TODO Auto-generated method stub String url = "jdbc:microsoft:sqlserver://192.168.5.20:1435;DatabaseName=emos2.2"; String driver = "com.microsoft.jdbc.sqlserver.SQLServerDriver"; try {Class.forName (driver); Connection conn = DriverManager.getConnection (url, "sa", "1234") If (conn.isClosed () = = true) {System.out.println ("SomeThing goes wrong");} PreparedStatement st = conn.prepareStatement ("select * from TestTable"); ResultSet rs = st.executeQuery () While (rs.next ()) {System.out.println (rs.getString ("guid")); System.out.println (rs.getString ("username")); System.out.println (rs.getBinaryStream ("content")) } catch (ClassNotFoundException e) {System.out.println ("SomeThing wrong"); System.out.println (e);} catch (SQLException e) {e.printStackTrace () } public static void main (String [] args) {/ / TODO Auto-generated method stub String url = "jdbc:microsoft:sqlserver://192.168.5.20:1435;DatabaseName=emos2.2"; String driver = "com.microsoft.jdbc.sqlserver.SQLServerDriver"; try {Class.forName (driver); Connection conn = DriverManager.getConnection (url, "sa", "1234") If (conn.isClosed () = = true) {System.out.println ("SomeThing goes wrong");} PreparedStatement st = conn.prepareStatement ("select * from TestTable"); ResultSet rs = st.executeQuery (); while (rs.next ()) {System.out.println ("guid")); System.out.println (rs.getString ("username")); System.out.println (rs.getBinaryStream ("content")) } catch (ClassNotFoundException e) {System.out.println ("SomeThing wrong"); System.out.println (e);} catch (SQLException e) {e.printStackTrace () }} and the third-party driver jtds1.2 solves the bug Java code public static void main (String [] args) {String url = "jdbc:jtds:sqlserver://192.168.5.20:1435/emos2.2"; String driver = "net.sourceforge.jtds.jdbc.Driver"; try {Class.forName (driver) Connection conn = DriverManager.getConnection (url, "sa", "1234"); if (conn.isClosed () = = true) {System.out.println ("SomeThing goes wrong");} PreparedStatement st = conn.prepareStatement ("select * from TestTable"); ResultSet rs = st.executeQuery () While (rs.next ()) {System.out.println (rs.getString ("guid")); System.out.println (rs.getString ("username")); System.out.println (rs.getBinaryStream ("content")) } catch (ClassNotFoundException e) {System.out.println ("SomeThing wrong"); System.out.println (e);} catch (SQLException e) {e.printStackTrace () }} on how to solve Microsoft's own JDBC resultset defects to share here, I hope that the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.

Tags: Microsoft type driver code fields queries defects content more statements order help good interest guys buddies data databases articles methods Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Information Shulou Technology Huawei MariaDB Xiaomi