In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article is to share with you the contents of JDBC instance analysis. Xiaobian thinks it is quite practical, so share it with everyone for reference. Let's follow Xiaobian and have a look.
JDBC instance premise:
1. SQL Server 2000: Enterprise Edition
2. SQL Server 2000 SP3 Upgrade Pack
You can download it here www.bossed.com.cn/download/detailcp.asp? id=74
3. SQL Server 2000 jdbc driver//this needs to find yourself!
4.jdk1.4 //The following example is this version
If the above conditions are met, do the following
1. Create a new database named jspdev and create a table named userinfo in it.
Include the following columns (Sno, Sname, Sage, Ssex, Sclass)
2. Start writing your own classes that connect to databases (I'm borrowing from others 'copyrights here), or you can use your own methods
import java.sql.*; class Testj{ public static void main(String args[]) { String RL = "jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=TESTDB"; String user ="jack";//Replace this with your own database user name String password = "jack";//Replace this with your own database user password String sqlStr = "select * from test_student"; try{ //exception handling statements are required here. Otherwise, it cannot be compiled! Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver"); System.out.println( "Class instantiation succeeded! " ); System.out.println("slkdjf"); Connection con = DriverManager.getConnection(RL,user,password); System.out.println( "Create connection object successfully! " ); Statement st = con.createStatement(); System.out.println( "Statement created successfully! " ); ResultSet rs = st.executeQuery( sqlStr ); System.out.println( "Operation data table succeeded! " ); System.out.println( "----------------! " ); while(rs.next()) { System.out.print(rs.getInt("Sno") + " "); System.out.print(rs.getString("Sname") + " "); System.out.print(rs.getInt("Sage") + " "); System.out.print(rs.getString("Ssex") + " "); System.out.println(rs.getString("Sclass")); } rs.close(); st.close(); con.close(); } catch(Exception err){ err.printStackTrace(System.out); } } }
The following debugging:
javac Testj.java
java Testj
If the JDBC instance correctly outputs something like:
Class instantiation successful!
slkdjf
Connection object created successfully!
Statement created successfully!
Data table operation succeeded!
----------------!
2000 Altitude 21 Male 12
Note: Here are a few points to note
1. Path problems:
You must configure your classpath path or it will report an error at compile time
java.lang.ClassNotFoundException: com.microsoft.jdbc.sqlserver.SQLServerDriver at java.net.URLClassLoader$1.run(URLClassLoader.java:199) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:187) at java.lang.ClassLoader.loadClass(ClassLoader.java:289) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:274) at java.lang.ClassLoader.loadClass(ClassLoader.java:235) at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:302) at java.lang.Class.forName0(Native Method) at java.lang.Class.forName(Class.java:141) at Test.main(Test.java:11)
Your path should be configured like this: you can see the help documentation there after installing the jdbc driver (in English);
//this means classpath = .; G:\Microsoft SQL Server 2000 \Driver for JDBC\lib\msbase.jar; G:\Microsoft SQL Server 2000 \Driver for JDBC\lib\mssqlserver.jar; G:\Microsoft SQL Server 2000 \Driver for JDBC\lib\msutil.jar;
Don't write it wrong!
2.SP3 Patch Issues:
You need to download and install the sp3 patch if you have the following problems at compile time
java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC]Error establis ng socket. at com.microsoft.jdbc.base.BaseExceptions.createException(Unknown Source) at com.microsoft.jdbc.base.BaseExceptions.getException(Unknown Source) at com.microsoft.jdbc.base.BaseExceptions.getException(Unknown Source) at com.microsoft.jdbc.sqlserver.tds.TDSConnection. (Unknown Source) at com.microsoft.jdbc.sqlserver.SQLServerImplConnection.open(Unknown Source) at com.microsoft.jdbc.base.BaseConnection.getNewImplConnection(Unknown Source) at com.microsoft.jdbc.base.BaseConnection.open(Unknown Source) at com.microsoft.jdbc.base.BaseDriver.connect(Unknown Source) at java.sql.DriverManager.getConnection(Unknown Source) at java.sql.DriverManager.getConnection(Unknown Source) at Test.main(Test.java:14)
3. permissions issues
If you have a problem like this,
Class instantiation successful!
slkdjf java.sql.SQLException: [Microsoft][SQL Server 2000 Driver for JDBC][SQL Server] Login failed for user 'jack'. Cause: Not associated with a trusted SQL Server connection. at com.microsoft.jdbc.base.BaseExceptions.createException(Unknown Source) at com.microsoft.jdbc.base.BaseExceptions.getException(Unknown Source) at com.microsoft.jdbc.sqlserver.tds.TDSRequest.processErrorToken(Unknown Source) at com.microsoft.jdbc.sqlserver.tds.TDSRequest.processReplyToken(Unknown Source) at com.microsoft.jdbc.sqlserver.tds.TDSLoginRequest.processReplyToken(Unknown Source) at com.microsoft.jdbc.sqlserver.tds.TDSRequest.processReply(Unknown Source) at com.microsoft.jdbc.sqlserver.SQLServerImplConnection.open(Unknown Source) at com.microsoft.jdbc.base.BaseConnection.getNewImplConnection(Unknown Source) at com.microsoft.jdbc.base.BaseConnection.open(Unknown Source) at com.microsoft.jdbc.base.BaseDriver.connect(Unknown Source) at java.sql.DriverManager.getConnection(DriverManager.java:512) at java.sql.DriverManager.getConnection(DriverManager.java:171) at Testj.main(Testj.java:14)
SQL Server login authentication mode is not set to mixed authentication mode, because SQL Server defaults to Windows authentication mode after installation, resulting in errors.
JDBC instance problem resolution: Start SQLSERVER Enterprise Manager, select the server to set authentication mode. Right-click on the server, select Properties from the pop-up menu, SQL Server will pop up the Properties dialog box Select Security Options in the Properties dialog box, select SQL Server and Windows under Authentication, and then OK.
Thank you for reading! About "JDBC instance analysis" this article is shared here, I hope the above content can be of some help to everyone, so that we can learn more knowledge, if you think the article is good, you can share it to let more people see it!
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.