想通過Domino7的Java代理讀寫SQL Server2005數據庫,jdbc1.2驅動已經安裝了。
microsoft說jdbc1.2支持1.4的jre。我單獨寫Java程序可以,把代碼放到domino代理裡就報錯了。
是不是domino7的jvm不支持jdbc1.2啊?
哪位試成功過?
注:用SQL Server2000的jdbc驅動訪問sqlserver2000數據庫沒問題。
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://192.168.1.2:1433;" +
"databaseName=test;user=sa;password=passWord";
// 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 10 * FROM table1";
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;
}
}
從jdbc1.2的samples裡copy過來的啊
domino後台報錯:
Java.lang.ExceptionInInitialzerError好像是初始化jdbc出錯啊
在Notes代理裡面用這個你首先得初始化Notes的一些對象的
import lotus.domino.*;
public class JavaAgent extends AgentBase {
對,我是這樣寫的
import lotus.domino.*;
public class JavaAgent extends AgentBase {
public main…
{
…
TestSQL t = new TestSQL();
t.WriteLog("aaa","bbb");
}
}