博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
OAF_JDBC系列2 - 通过JDBC连接SQLSERVER数据库DriverManager.getConnection
阅读量:5937 次
发布时间:2019-06-19

本文共 3472 字,大约阅读时间需要 11 分钟。

d

 

       try{

          Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
          String connectionSQLServer = "jdbc:sqlserver://gavinmysql.com;databaseName=MDS;user=ViewMDSUserReadonly;password=MDSReadonly;";
          Statement stmtSource = null;
          Statement xstm = null;
          ResultSet rsSource = null;
          Connection msdbConn = DriverManager.getConnection(connectionSQLServer);
          try{
              userGroup[] users = new userGroup[90000];
              String msSql = null;
             
              if (xxAccountName !=null && !"".equals(xxAccountName))
              {
                msSql ="select ID,AdsPath,AccountName,AccountType,EmployeeNo,Name,DisplayName,Description, " +
                        "DepartmentID,DepartmentName,MemberOf,ObjectClass,Mail,TelephoneNumber,Mobile," +
                        "UserPrincipalName,SN,GivenName,Title,Department,Company,DirectReports,ManagerID," +
                        "Manager,OrderID,SyncTime,OrgID,OrgNumber,OrgNickNumber,OrgName,OrgDisplayName," +
                        "Disabled,Deleted from dbo.View_Mds_User where upper(AccountName)=" +"'"+ xxAccountName.toUpperCase() +
                        "' and Disabled="+"'"+"0"+"'";
              }else
              {
                    msSql ="select ID,AdsPath,AccountName,AccountType,EmployeeNo,Name,DisplayName,Description, " +
                            "DepartmentID,DepartmentName,MemberOf,ObjectClass,Mail,TelephoneNumber,Mobile," +
                            "UserPrincipalName,SN,GivenName,Title,Department,Company,DirectReports,ManagerID," +
                            "Manager,OrderID,SyncTime,OrgID,OrgNumber,OrgNickNumber,OrgName,OrgDisplayName," +
                            "Disabled,Deleted from dbo.View_Mds_User where Disabled="+"'"+"0"+"'";
              }
              
              stmtSource = msdbConn.createStatement();
              rsSource = stmtSource.executeQuery(msSql);
              int r =0;
              while (rsSource.next()){
                  users[r] = new userGroup();
                  users[r].strID = rsSource.getString("ID");
                  users[r].strAdsPath = rsSource.getString("AdsPath");
                  users[r].strAccountName = rsSource.getString("AccountName");
                  users[r].strAccountType = rsSource.getString("AccountType");
                  users[r].strEmployeeNo = rsSource.getString("EmployeeNo");
                  users[r].strName = rsSource.getString("Name");
                  users[r].strDisplayName = rsSource.getString("DisplayName");
                  users[r].strDescription = rsSource.getString("Description");
                  users[r].strDepartmentID = rsSource.getString("DepartmentID");
                  users[r].strDepartmentName = rsSource.getString("DepartmentName");
                  users[r].strMemberOf = rsSource.getString("MemberOf");
                  users[r].strObjectClass = rsSource.getString("ObjectClass");
                  users[r].strMail = rsSource.getString("Mail");
                  users[r].strTelephoneNumber = rsSource.getString("TelephoneNumber");
                  users[r].strMobile = rsSource.getString("Mobile");
                  users[r].strUserPrincipalName = rsSource.getString("UserPrincipalName");
                  users[r].strSN = rsSource.getString("SN");
                  users[r].strGivenName = rsSource.getString("GivenName");
                  users[r].strTitle = rsSource.getString("Title");
                  users[r].strDepartment = rsSource.getString("Department");
                  users[r].strCompany = rsSource.getString("Company");
                  users[r].strDirectReports = rsSource.getString("DirectReports");
                  users[r].strManagerID = rsSource.getString("ManagerID");
                  users[r].strManager = rsSource.getString("Manager");
                  users[r].strOrderID = rsSource.getString("OrderID");
                  users[r].strSyncTime = rsSource.getString("SyncTime");
                  users[r].strOrgID = rsSource.getString("OrgID");
                  users[r].strOrgNumber = rsSource.getString("OrgNumber");
                  users[r].strOrgNickNumber = rsSource.getString("OrgNickNumber");
                  users[r].strOrgName = rsSource.getString("OrgName");
                  users[r].strOrgDisplayName = rsSource.getString("OrgDisplayName");
                  users[r].strDisabled = rsSource.getString("Disabled");
                  users[r].strDeleted = rsSource.getString("Deleted");
                  //users[r].strChangeTime = rsSource.getString("ChangeTime");
                  r += 1;
              }

转载地址:http://edvtx.baihongyu.com/

你可能感兴趣的文章