Pay attention to the following points:
1. Import sqljdbd to the Project
2. If Tomcat is used, msbase, mssqlservr, and msutil jar packages must be added to the lib directory.
3. If you write the JAVA client directly, you must add the Three JAR files to the project's Libraries.
1 String driver = "com. microsoft. jdbc. sqlserver. SQLServerDriver ";
2 String url = "jdbc: microsoft: sqlserver: // 192.168.0.20: 1433; DatabaseName = fqit ";
3
4 try {
5 Class. forName (driver );
6 Connection conn = DriverManager. getConnection (url, "it11", "luck2000 ");
7 PreparedStatement pstmt = conn. prepareStatement ("select * from dept ");
8 ResultSet rs1_pstmt.exe cuteQuery ();
9 while (rs. next ()){
10 out. println (rs. getString ("dept "));
11 out. println ("<br> ");
12}
13 rs. close ();
14 pstmt. close ();
15 conn. close ();
16} catch (ClassNotFoundException e ){
17 e. printStackTrace ();
18} catch (SQLException e ){
19 e. printStackTrace ();
20}