A
allex
Класс представляет собой связку Notes и SQL. Агент запускается при активировании ссылки [http://host/db.nsf/agent?OpenAgent&id=111111]. Далее происходит обработка запроса к SQL по полученному праметру id=111111, затем в базе Domino создается notes-документ с параметрами выбранными из запроса
<div class="sp-wrap"><div class="sp-head-wrap"><div class="sp-head folded clickable">Java class по работе Notes&SQL </div></div><div class="sp-body"><div class="sp-content">
<!--shcode--><pre><code class='java'>import lotus.domino.*;
import java.util.Vector;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
import java.sql.ResultSet;
import java.net.*;
import java.io.*;
import java.util.*;
public class JavaAgent extends AgentBase {
public static java.util.Hashtable parseQueryString(String queryString) {
StringTokenizer tokens = new StringTokenizer(queryString, "&");
Hashtable params = new Hashtable();
while (tokens.hasMoreTokens()) {
String token = tokens.nextToken();
int equalIdx = token.indexOf('=');
if (equalIdx != -1 && !token.equalsIgnoreCase("OpenAgent")) {
String name = token.substring(0, equalIdx);
System.out.println("name " + name);
String value = token.substring(equalIdx + 1);
System.out.println("value " + value);
params.put(name, value);
}
}
return params;
}
public void NotesMain() {
try {
Session session = getSession();
AgentContext agentContext = session.getAgentContext();
Document webdoc = agentContext.getDocumentContext();
PrintWriter pw = getAgentOutput();
// System.out.println("сессии инициировались");
String qs = webdoc.getItemValueString("Query_String");
java.util.Hashtable ht = parseQueryString(qs);
String id = (String) ht.get("id");
// pw.println("ID : " + id);
try {
Class.forName("com.mysql.jdbc.Driver").newInstance();
System.out.println("Драйвер загружен");
Connection conn = null;
try {
conn = DriverManager.getConnection("jdbc:mysql://conect);
System.out.println("Подключение установлено");
Statement stmt = null;
try {
stmt = conn.createStatement();
System.out.println("id " + id);
String Query = "SELECT * FROM pr_data WHERE auth = " + '"'+id+ '"';// + " ORDER BY id";
//String Query = "SELECT * FROM pr_data";
System.out.println("Запрос " + Query);
ResultSet rs = null;
try {
rs = stmt.executeQuery(Query);
System.out.println("Запрос выполняется");
Database db = agentContext.getCurrentDatabase();
Document doc = db.createDocument();
while (rs.next()) {
int theid= rs.getInt("id");
String fname = rs.getString("fname");
String mname = rs.getString("mname");
String lname = rs.getString("lname");
String message = rs.getString("message");
String email = rs.getString("email");
String auth = rs.getString("auth");
String pindex = rs.getString("pindex");
String pregion = rs.getString("pregion");
String plocality = rs.getString("plocality");
String pstreet = rs.getString("pstreet");
String phome = rs.getString("phome");
String pcorps = rs.getString("pcorps");
String pflat = rs.getString("pflat");
System.out.println("Переменные присвоены");
System.out.println("auth_code = " + auth );
System.out.println("id = " + theid + " ---> ФИО = " + fname + " " + mname +" "+ lname);
System.out.println("id = " + theid + " ---> Почтовый адрес = " + pindex +" "+ pregion +" "+ plocality +" "+ pstreet +" "+ phome +" "+ pcorps +" "+ pflat);
System.out.println("id = " + theid + " ---> Электронныйый адрес = " + email);
System.out.println("id = " + theid + " ---> Текст обращения = " + message );
System.out.println("_________________________________");
doc.replaceItemValue("Form", "rlo");
doc.replaceItemValue("auth", id);
doc.replaceItemValue("FIO", fname + " " + mname +" "+ lname);
doc.replaceItemValue("Address", pindex +" "+ pregion +" "+ plocality +" ул."+ pstreet +" д."+ phome +" корп."+ pcorps +" кв."+ pflat);
doc.replaceItemValue("email", email);
doc.replaceItemValue("Annotation", message);
doc.computeWithForm(false, false);
doc.save();
}
}
catch (SQLException ex) {
System.out.println("SQLException: " + ex.getMessage());
System.out.println("SQLState: " + ex.getSQLState());
System.out.println("VendorError: " + ex.getErrorCode());
}
finally {
if (rs != null) {
try {
rs.close();
}
catch (SQLException ex) {}
rs = null;
}
}
}
finally {
if (stmt != null) {
try {
stmt.close();
}
catch (SQLException ex) {}
stmt = null;
} //if
} //finally
}
catch (SQLException ex) {
System.out.println("On connect SQLException: " + ex.getMessage());
System.out.println("SQLState: " + ex.getSQLState());
System.out.println("VendorError: " + ex.getErrorCode());
}
}
catch (Exception ex) {
System.out.println("SQLException: " + ex.getMessage());
}
}
catch(Exception e) {
e.printStackTrace();
}
}
}[/CODE]
<div class="sp-wrap"><div class="sp-head-wrap"><div class="sp-head folded clickable">Java class по работе Notes&SQL </div></div><div class="sp-body"><div class="sp-content">
<!--shcode--><pre><code class='java'>import lotus.domino.*;
import java.util.Vector;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
import java.sql.ResultSet;
import java.net.*;
import java.io.*;
import java.util.*;
public class JavaAgent extends AgentBase {
public static java.util.Hashtable parseQueryString(String queryString) {
StringTokenizer tokens = new StringTokenizer(queryString, "&");
Hashtable params = new Hashtable();
while (tokens.hasMoreTokens()) {
String token = tokens.nextToken();
int equalIdx = token.indexOf('=');
if (equalIdx != -1 && !token.equalsIgnoreCase("OpenAgent")) {
String name = token.substring(0, equalIdx);
System.out.println("name " + name);
String value = token.substring(equalIdx + 1);
System.out.println("value " + value);
params.put(name, value);
}
}
return params;
}
public void NotesMain() {
try {
Session session = getSession();
AgentContext agentContext = session.getAgentContext();
Document webdoc = agentContext.getDocumentContext();
PrintWriter pw = getAgentOutput();
// System.out.println("сессии инициировались");
String qs = webdoc.getItemValueString("Query_String");
java.util.Hashtable ht = parseQueryString(qs);
String id = (String) ht.get("id");
// pw.println("ID : " + id);
try {
Class.forName("com.mysql.jdbc.Driver").newInstance();
System.out.println("Драйвер загружен");
Connection conn = null;
try {
conn = DriverManager.getConnection("jdbc:mysql://conect);
System.out.println("Подключение установлено");
Statement stmt = null;
try {
stmt = conn.createStatement();
System.out.println("id " + id);
String Query = "SELECT * FROM pr_data WHERE auth = " + '"'+id+ '"';// + " ORDER BY id";
//String Query = "SELECT * FROM pr_data";
System.out.println("Запрос " + Query);
ResultSet rs = null;
try {
rs = stmt.executeQuery(Query);
System.out.println("Запрос выполняется");
Database db = agentContext.getCurrentDatabase();
Document doc = db.createDocument();
while (rs.next()) {
int theid= rs.getInt("id");
String fname = rs.getString("fname");
String mname = rs.getString("mname");
String lname = rs.getString("lname");
String message = rs.getString("message");
String email = rs.getString("email");
String auth = rs.getString("auth");
String pindex = rs.getString("pindex");
String pregion = rs.getString("pregion");
String plocality = rs.getString("plocality");
String pstreet = rs.getString("pstreet");
String phome = rs.getString("phome");
String pcorps = rs.getString("pcorps");
String pflat = rs.getString("pflat");
System.out.println("Переменные присвоены");
System.out.println("auth_code = " + auth );
System.out.println("id = " + theid + " ---> ФИО = " + fname + " " + mname +" "+ lname);
System.out.println("id = " + theid + " ---> Почтовый адрес = " + pindex +" "+ pregion +" "+ plocality +" "+ pstreet +" "+ phome +" "+ pcorps +" "+ pflat);
System.out.println("id = " + theid + " ---> Электронныйый адрес = " + email);
System.out.println("id = " + theid + " ---> Текст обращения = " + message );
System.out.println("_________________________________");
doc.replaceItemValue("Form", "rlo");
doc.replaceItemValue("auth", id);
doc.replaceItemValue("FIO", fname + " " + mname +" "+ lname);
doc.replaceItemValue("Address", pindex +" "+ pregion +" "+ plocality +" ул."+ pstreet +" д."+ phome +" корп."+ pcorps +" кв."+ pflat);
doc.replaceItemValue("email", email);
doc.replaceItemValue("Annotation", message);
doc.computeWithForm(false, false);
doc.save();
}
}
catch (SQLException ex) {
System.out.println("SQLException: " + ex.getMessage());
System.out.println("SQLState: " + ex.getSQLState());
System.out.println("VendorError: " + ex.getErrorCode());
}
finally {
if (rs != null) {
try {
rs.close();
}
catch (SQLException ex) {}
rs = null;
}
}
}
finally {
if (stmt != null) {
try {
stmt.close();
}
catch (SQLException ex) {}
stmt = null;
} //if
} //finally
}
catch (SQLException ex) {
System.out.println("On connect SQLException: " + ex.getMessage());
System.out.println("SQLState: " + ex.getSQLState());
System.out.println("VendorError: " + ex.getErrorCode());
}
}
catch (Exception ex) {
System.out.println("SQLException: " + ex.getMessage());
}
}
catch(Exception e) {
e.printStackTrace();
}
}
}[/CODE]