我们主要使用MSSQL并将数据库连接到数据库用户或活动目录用户。我们将jtds库用于活动目录用户。现在我们开始使用Oracle数据库,我认为jtds不支持Oracle。在开始Oracle连接之前,我尝试通过模拟不使用jtds来连接MSSQL和integratedSecurity选项。我在模仿期间没有收到任何错误,但我检查连接数据库的用户。用户显示为登录用户,但应显示模拟用户。我分享我的代码;
WinNT.HANDLEByReference handle = new WinNT.HANDLEByReference();
boolean successful = Advapi32.INSTANCE.LogonUser
("userB", "domain", "userBpass", WinBase.LOGON32_LOGON_NETWORK,
WinBase.LOGON32_PROVIDER_DEFAULT, handle);
String DB = "jdbc:sqlserver://DEVSQL:1433;databaseName=ZONE;integratedSecurity=true";
Connection connection= DriverManager.getConnection(DB);
Driver d = (Driver)Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver").newInstance();
String sql = "SELECT DB_NAME(dbid) as DBName, COUNT(dbid) as NumberOfConnections, loginame as LoginName FROM sys.sysprocesses WHERE dbid > 0 GROUP BY dbid, loginame";
PreparedStatement psmt = connection.prepareStatement(sql);
ResultSet rs = psmt.executeQuery();
if (rs != null && rs.next())
System.out.println(rs.getString(3));//it shows userA(logged user), but it should show userB
非常感谢任何关于此的指导。谢谢!