Avaya Accessing Orchestration designer variables in servlet node



Setting value to OD variables in Servlet node:

mySession.getVariableField(IProjectVariables.C__COUNTS,IProjectVariables.C__COUNTS_FIELD_MAXNI).setValue("");

Writing trace info

TraceInfo.trace(ITraceInfo.TRACE_LEVEL_INFO,this.getClass().getName() + " -> Value - " + mySession.getVariableField("OD", "OD_complex").getStringValue(), mySession);



Read more »

Configure ddlog4j rolling files with index and size limit java



Configure below properties to configure Rolling and set limit to file size and index limit of ddlog4j library properties

log4j.appender.Rapp=org.apache.log4j.RollingFileAppender
log4j.appender.Rapp.File=C:/xx/logs/app/data/log/report.log
log4j.appender.Rapp.MaxFileSize = 10MB
log4j.appender.Rapp.MaxBackupIndex = 5
log4j.appender.Rapp.DatePattern='.'yyyy-MM-dd
log4j.appender.Rapp.layout=org.apache.log4j.PatternLayout
log4j.appender.Rapp.layout.ConversionPattern=%d{dd/MM/yyyy HH:mm:ss:SSS} %5p - %m%n
log4j.appender.Rapp.Encoding=UTF-8
Read more »

Java code to connect Oracle database using JDBC driver



Making JDBC Query to database using code

 Connection conn=null;
 ResultSet rs1=null;

try
{
 PreparedStatement ps1=null;

Class.forName("oracle.jdbc.driver.OracleDriver");

conn = DriverManager.getConnection( "jdbc:oracle:thin:@127.0.0.1:1521:XE", "system", "manager");

Statement stmt = conn.createStatement();

rs1= stmt.executeQuery("select SUBJECT from HR.SUBJECT ");
}
catch(SQLException e)
{
while((e = e.getNextException()) != null) out.println(e.getMessage() + "");
  }
catch(ClassNotFoundException e)
{
 }


Reading the ResultSet

 try{
while(rs1.next()){
String ComboBoxValue1=rs1.getString("SUBJECT")  ; 
 }
                 catch(Exception exp){
 out.println("exception in populating subjects");
 }

Read more »

Servlet Code to Update records in SQL database using Tomcat server

In this post we will illustrate how to Search and display information from database.
This post is continued from previous post have a look on how to do:

1. Database settings and Insetion of data into SQL database.
2. Searching information from Database
3. Deleting informstion from database

Create a html form upinfo.html

<html>
<head>
<h1><u>student form</u></h1>
</head>
<body bgcolor="DarkSalmon">
<form name=Student method=POST action=http://localhost:8080/examples/servlet/upinfo>
<font face="Copperplate Gothic Bold">STUDENT NAME</font face>:<input type="text" name="t1" size="30"><p><br>
<font face="Copperplate Gothic Bold">ID</font face>:<input type="text" name="t2" size="30"><p><br>
<font face="Copperplate Gothic Bold">AGE</font face>:<input type="text" name="t3" size="30"><p><br>
<font face="Copperplate Gothic Bold">BRANCH</font face>:<input type="text" name="t4" size="30"><p><br>
<br>
<input type="submit" value="submit">
</form>
</body>
</html>


Now Create a up.java which has the actual logic for deleting information from database.

import java.io.*;
import java.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class upinfo extends HttpServlet
{
public void doPost(HttpServletRequest req,HttpServletResponse res)
throws ServletException,IOException
{
doGet(req,res);
}
public void doGet(HttpServletRequest req,HttpServletResponse res)
throws ServletException,IOException
{
PrintWriter out=res.getWriter();
res.setContentType("text/html");
String s1=req.getParameter("t1");
String s2=req.getParameter("t2");
String s3=req.getParameter("t3");
String s4=req.getParameter("t4");
out.println("<html><body><h1>............................servlet updating..........:):).......</h1></body></html>");
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("jdbc:odbc:student1","sa","sa");
out.println("<html><body><h4>connectiopn established........</h4></body></html>");
String query="update studentinfo set name1='"+s1+"',age='"+s3+"',branch='"+s4+"'where id1='"+s2+"'";
out.println("<html><body><h3>updating from database.......</h3></body></html>");
Statement stmt=con.createStatement();
out.println("<h2>:):):)</h2>");
ResultSet rs=stmt.executeQuery(query);
out.println("<html><body><h4>thank you for registrating.......</h4></body></html>");
con.close();
}
catch(Exception e)
{
System.out.println("Error in login:"+e);
}
}
}


Read more »

Servlet Code to Delete information from SQL database Tomcat server

In this post we will illustrate how to delete information from database.
This post is continued from previous post have a look on how to do:
1. Database settings and insetion of data into SQL database.
2. Searching information from database.

Create a html form delinfo.html

<html>
<head>
<h1><u>student form</u></h1>
</head>
<body bgcolor="DarkSalmon">
<form name=Student method=POST action=http://localhost:8080/examples/servlet/delinfo>

<font face="Copperplate Gothic Bold">ID</font face>:<input type="text" name="t2" size="30"><p><br>
<br>
<input type="submit" value="submit">
</form>
</body>
</html>


Now Create a delinfo.java which has the actual logic for deleting information from database.

import java.util.*;
import java.io.*;
import java.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class delinfo extends GenericServlet
{
public void service(ServletRequest req,ServletResponse res)
throws ServletException,IOException
{
try
{
PrintWriter out=res.getWriter();
res.setContentType("text/html");
String s2=req.getParameter("t2");
out.println("<html><body><h1>............................servlet deletion working..........:):).......</h1></body></html>");
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("jdbc:odbc:student1","sa","sa");
out.println("<html><body><h4>connectiopn established........</h4></body></html>");
if(con!=null)
{
out.println("<html><body><h4>connection established........</h4></body></html>");
Statement stmt=con.createStatement();
ResultSet rs=stmt.executeQuery("delete from studentinfo where id1='"+s2+"'");
out.println("<html><body><h4>deleted from database.......</h4></body></html>");
stmt.close();
}



con.close();
out.close();


}
catch(Exception e)
{}
}
}

Deleting information from SQL database
Deleting information from SQL database




Read more »

Servlet Code for Searching information from SQL database Tomcat Server

In this post we will illustrate how to Search and display information from database.This post is continued from previous post have a look on how to do:

1. Database settings & Insetion of data into SQL database.

Create a HTML page named searchinfo.html

<html>
<head>
<h1><u>student form</u></h1>
</head>
<body bgcolor="DarkSalmon">
<form name=Student method=POST action=http://localhost:8080/examples/servlet/searchinfo>

<font face="Copperplate Gothic Bold">ID</font face>:<input type="text" name="t2" size="30"><p><br>
<br>
<input type="submit" value="submit">
</form>
</body>
</html>


Now Create a Searchinfo.java which has the actual logic for seraching information and displaying it.


import java.util.*;
import java.io.*;
import java.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class searchinfo extends GenericServlet
{
public void service(ServletRequest req,ServletResponse res)
throws ServletException,IOException
{
try
{
PrintWriter out=res.getWriter();
res.setContentType("text/html");
String s2=req.getParameter("t2");
out.println("<html><body><h1>............................servlet retrieval working..........:):).......</h1></body></html>");
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("jdbc:odbc:student1","sa","sa");
out.println("<html><body><h4>connectiopn established........</h4></body></html>");
if(con!=null)
{
out.println("<html><body><h4>connection established........</h4></body></html>");
Statement stmt=con.createStatement();
ResultSet rs=stmt.executeQuery("select * from studentinfo where id1='"+s2+"'");
out.println("<html><body><h4>retrieved from database.......</h4></body></html>");
ResultSetMetaData md=rs.getMetaData();
out.println("<html>");
out.println("<body>");
out.println("<head>");
out.println("retrieval servlet");
out.println("</head>");
out.println("<table border=1>");
out.println("<tr><td>student name</td><td>id</td><td>age</td><td>branch</td></tr>");
while(rs.next())
{
for(int i=1;i<md.getColumnCount();i++)
{
out.println("<tr><td>"+rs.getString(i++)+"</td><td>"+rs.getString(i++)+"</td><td>"+rs.getString(i++)+"</td><td>"+rs.getString(i++)+"</td></tr>");
out.println("***");
out.println("</table></body></html>");
}
}

rs.close();
stmt.close();
con.close();
out.close();

}
}
catch(Exception e)
{}
}
}

Searching information from SQL database
Searching information from SQL database

Read more »

Servlet code to insert data into MS SQL database using Tomcat Server

Unlike JSP and PHP Servlet is also server side scripting language. Servlet is Java based, Here this post we are going to illustrate how to add, delete , update and Search data from a form interacting with SQL database.
For consideration we will need tomcat server installed running on the system by default at port 8080 and sql database running on the system.

STEP 1:

Create database in Microsoft sql Query analyser .
Create table with 4 fields viz StudentName , ID , Age and Branch.
->Keep ID as  INT and set it as primary key
->keep StudentName as VARCHAR(100)
->keep age as INTEGER
->Keep Branch as VARCHAR(100)

STEP 2 :

This code is only for addition of information to the database

Create a html page as follows:

studentinfo.html

<html>
<head>
<h1><u>student form</u></h1>
</head>
<body bgcolor="DarkSalmon">
<form name=Student method=POST action=http://localhost:8080/examples/servlet/studentinfo>
<font face="Copperplate Gothic Bold">STUDENT NAME</font face>:<input type="text" name="t1" size="30"><p><br>
<font face="Copperplate Gothic Bold">ID</font face>:<input type="text" name="t2" size="30"><p><br>
<font face="Copperplate Gothic Bold">AGE</font face>:<input type="text" name="t3" size="30"><p><br>
<font face="Copperplate Gothic Bold">BRANCH</font face>:<input type="text" name="t4" size="30"><p><br>
<br>
<input type="submit" value="submit">
</form>
</body>
</html>

Now Create a page named studentinfo.java which has actual logic to interact with SQL database and insert information.

import java.io.*;
import java.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class studentinfo extends HttpServlet
{
public void doPost(HttpServletRequest req,HttpServletResponse res)
throws ServletException,IOException
{
doGet(req,res);
}
public void doGet(HttpServletRequest req,HttpServletResponse res)
throws ServletException,IOException
{
PrintWriter out=res.getWriter();
res.setContentType("text/html");
String s1=req.getParameter("t1");
String s2=req.getParameter("t2");
String s3=req.getParameter("t3");
String s4=req.getParameter("t4");
out.println("<html><body><h1>............................servlet running..........:):).......</h1></body></html>");
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("jdbc:odbc:student1","sa","sa");
out.println("<html><body><h4>connectiopn established........</h4></body></html>");
String query="insert into studentinfo values('"+s1+"','"+s2+"','"+s3+"','"+s4+"')";
out.println("<html><body><h3>inserting into database.......</h3></body></html>");
Statement stmt=con.createStatement();
out.println("<h2>:):):)</h2>");
ResultSet rs=stmt.executeQuery(query);
out.println("<html><body><h4>thank you for registrating.......</h4></body></html>");
con.close();
}
catch(Exception e)
{
System.out.println("Error in login:"+e);
}
}
}

inserting to SQL databse using servlet

Read more »

JSP Java Code to Search record in SQL database using Apache server


searchstud.jsp

<%@page session="true"import="java.io.*"%>
<html>
<body bgcolor="#d0d0d0">
<br></br>
<br></br>
<br></br>
<h2><center>enter stuent details</center></h2>
<form name="searchstud"action="searchstudinfo.jsp"method="post">
<table border="2"align=center>
<tr><td>
<b>enter the id u want to search:</b>
<input type="text"name="id"/>
<br/>
<br/>
</td></tr>
</table>
<center>
<input type="submit"value="submit"/>
<input type="reset"value="reset"/>
</form>
</body>
</html>

searchstudinfo.jsp

<%@page session="true"import="java.io.*"%>
<html>
<body bgcolor="#d0d0d0">
<br></br>
<br></br>
<%@page import="java.sql.*"%>
<%@page import="java.util.*"%>
<table>
<tr>
<th>name</th>
<th>id</th>
<th>age</th>
<th>branch</th>
</tr>
<%
Connection con=null;
Statement stmt=null;
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con=DriverManager.getConnection("jdbc:odbc:student1","sa","sa");
stmt=con.createStatement();
String s2=request.getParameter("id");
%>
<%

ResultSet res=stmt.executeQuery("select * from studentinfo where id1='"+s2+"'");
while(res.next())
{
%>
<tr>
<td><%=res.getString("name1")%></td>
<td><%=res.getString("id1")%></td>
<td><%=res.getString("age")%></td>
<td><%=res.getString("branch")%></td>
</tr>
<%
}
%>
</table>
</body>
</html>


OUTPUT:

Read more »

JSP Java code to Update Record in SQL database using Tomcat server

upstud.jsp

<%@page session="true"import="java.io.*"%>
<html>
<body bgcolor="#d0d0d0">
<br></br>
<br></br>
<br></br>
<h2><center>enter stuent details</center></h2>
<form name="upstud"action="upstudinfo.jsp"method="post">
<table border="2"align=center>
<tr><td>
<b>student name:</b>
<input type="text"name="name"/>
<br/>
<br/>
</td></tr>
<tr><td>
<b>id:</b>
<input type="text"name="id"/>
<br/>
<br/>
</td></tr>
<tr><td>
<b>age:</b>
<input type="text"name="age"/>
<br/>
<br/>
</td></tr>
<tr><td>
<b>branch:</b>
<input type="text"name="branch"/>
<br/>
<br/>
</td></tr>
</table>
<center>
<input type="submit"value="submit"/>
<input type="reset"value="reset"/>
<input type="button"value="delete"/>
</form>
</body>
</html>

upstudinfo.jsp

<%@page session="true"import="java.io.*"%>
<html>
<body bgcolor="#d0d0d0">
<br></br>
<br></br>
<%@page import="java.sql.*"%>
<%@page import="java.util.*"%>
<%
Connection con=null;
Statement stmt=null;
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con=DriverManager.getConnection("jdbc:odbc:student1","sa","sa");
try
{
String s1=request.getParameter("name");
String s2=request.getParameter("id");
String s3=request.getParameter("age");
String s4=request.getParameter("branch");
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con=DriverManager.getConnection("jdbc:odbc:student1","sa","sa");
stmt=con.createStatement();
stmt.executeUpdate("update studentinfo set name1='"+s1+"',age='"+s3+"',branch='"+s4+"'where id1='"+s2+"'");
%>
data updated successfully...........
<%
stmt.close();
stmt=null;
}
finally
{
if(con!=null)
{
con.close();
}
}
%>
</body>
</html>

OUTPUT:


Read more »

JSP Java code to Delete Record using SQL and apache server

delstud.jsp

<%@page session="true"import="java.io.*"%>
<html>
<body bgcolor="#d0d0d0">
<br></br>
<br></br>
<br></br>
<h2><center>enter stuent details</center></h2>
<form name="delstud"action="delstudinfo.jsp"method="post">
<table border="2"align=center>
<tr><td>
<b>id:</b>
<input type="text"name="id"/>
<br/>
<br/>
</td></tr>
</table>
<center>
<input type="submit"value="submit"/>
<input type="reset"value="reset"/>
<input type="button"value="delete"/>
</form>
</body>
</html>


delstudinfo.jsp

<%@page session="true"import="java.io.*"%>
<html>
<body bgcolor="#d0d0d0">
<br></br>
<br></br>
<%@page import="java.sql.*"%>
<%@page import="java.util.*"%>
<%
Connection con=null;
Statement stmt=null;
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con=DriverManager.getConnection("jdbc:odbc:student1","sa","sa");
try
{

String s2=request.getParameter("id");

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con=DriverManager.getConnection("jdbc:odbc:student1","sa","sa");
stmt=con.createStatement();
stmt.executeUpdate("delete from studentinfo where id1='"+s2+"'");
%>
data deleted successfully...........
<%
stmt.close();
stmt=null;
}
finally
{
if(con!=null)
{
con.close();
}
}
%>
</body>
</html>

OUTPUT:


Read more »