In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-06 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
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.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.