Lotus agent demo:
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.*;
public class TestSQL
{
public int WriteLog(String unid, String strOperator, String strOperation)
{
try {
// Create a variable for the connection string.
String connectionUrl = "jdbc:sqlserver://10.1.1.1:1433;" +
"databaseName=NorthWind;user=sa;password=sa";
// Declare the JDBC objects.
Connection con = null;
Statement stmt = null;
ResultSet rs = null;
try {
// Establish the connection.
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
con = DriverManager.getConnection(connectionUrl);
// Create and execute an SQL statement that returns some data.
String SQL = "select top 5 event.event_id as event_id,event.event_name+event.event_desc as Problem_Request_Desc,APM_ACCOUNTABILITY.acct_party_name as business_group,apm_app.app_short_name as system_affected,event.effort from event left join app_event on app_event.event_id=event.event_id left join apm_app on app_event.app_id=apm_app.app_id left join APM_ACCOUNTABILITY on APM_ACCOUNTABILITY.app_id=apm_app.app_id where APM_ACCOUNTABILITY.ACCT_ROLE='PST Business Group'";
stmt = con.createStatement();
rs = stmt.executeQuery(SQL);
// Iterate through the data in the result set and display it.
while (rs.next()) {
System.out.println(rs.getString(1) + " " + rs.getString(2));
}
}
// Handle any errors that may have occurred.
catch (Exception e) {
e.printStackTrace();
}
finally {
if (rs != null) try { rs.close(); } catch(Exception e) {}
if (stmt != null) try { stmt.close(); } catch(Exception e) {}
if (con != null) try { con.close(); } catch(Exception e) {}
}
System.out.println("SQL Server 2005 数据库连接成功");
}
catch (Exception e)
{
System.out.print("access to sql server 2005 error : " + e.getMessage());
e.printStackTrace();
return 1;
}
return 0;
}
}