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;
public class JavaAgent extends AgentBase {
public void NotesMain(String id) {
System.out.println("void инициировалась");
try {
Session session = getSession();
AgentContext agentContext = session.getAgentContext();
Statement stmt = null;
ResultSet rs = null;
Connection conn = null;
System.out.println("сессии инициировались");
try {
Class.forName("com.mysql.jdbc.Driver").newInstance();
System.out.println("Драйвер загружен");
}
catch (Exception ex)
{
System.out.println("SQLException: " + ex.getMessage());
}
try {
conn = DriverManager.getConnection("jdbc:mysql://konect");
System.out.println("Подключение установлено");
}
catch (SQLException ex)
{
System.out.println("On connect SQLException: " + ex.getMessage());
System.out.println("SQLState: " + ex.getSQLState());
System.out.println("VendorError: " + ex.getErrorCode());
}
try {
stmt = conn.createStatement();
id = "4isNNEkEA8kNhn9B";
String Query = "SELECT * FROM pr_data WHILE auth=" + '"'+ id +'"';
System.out.println("Запрос" + Query);
try {
rs = stmt.executeQuery(Query);
System.out.println("Запрос выполняется");
}
catch(SQLException ex)
{
System.out.println("on JOIN SQLException: " + ex.getMessage());
System.out.println("SQLState: " + ex.getSQLState());
System.out.println("VendorError: " + ex.getErrorCode());
}
Database db = agentContext.getCurrentDatabase();
Document doc = db.createDocument();
Vector vauth = new Vector();
Vector vfio = new Vector();
Vector vaddress = new Vector();
Vector vemail = new Vector();
Vector vmessage = new Vector();
while (rs.next()) {
// retrieve and print the values for the current row
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("_________________________________");
vauth.addElement(auth);
vfio.addElement(fname + " " + mname +" "+ lname);
vaddress.addElement(pindex +" "+ pregion +" "+ plocality +" "+ pstreet +" "+ phome +" "+ pcorps +" "+ pflat);
vemail.addElement(email);
vmessage.addElement(message);
}
doc.replaceItemValue("Form", "rlo");
doc.appendItemValue("FIO", vfio);
doc.appendItemValue("Address", vaddress);
doc.appendItemValue("email", vemail);
doc.appendItemValue("Annotation", vmessage);
doc.computeWithForm(false, false);
doc.save();
} finally {
if (rs != null) {
try {
rs.close();
} catch(SQLException ex) {}
rs = null;
} //if
if (stmt != null) {
try {
stmt.close();
} catch(SQLException ex) {}
stmt = null;
} //if
} //finally
} catch(Exception e) {
e.printStackTrace();
}
}
}