Saturday, November 12, 2011

To Add record in MS Access using Servlet JDBC

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.sql.*;
public class Entry extends HttpServlet
{
Connection cn;
String s1,s2,s3;
public void service(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException
{
res.setContentType("text/html");
PrintWriter out = res.getWriter();
out.println("<HTML><HEAD><TITLE>Emai List.</TITLE>");
out.println("</HEAD>");
out.println("<BODY bgColor=blanchedalmond text=#008000 topMargin=0>");
s1 = req.getParameter("t1");
s2 = req.getParameter("t2");
s3 = req.getParameter("t3");
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
cn = DriverManager.getConnection("jdbc:odbc:emaildb", "admin", "");
Statement st=cn.createStatement();
out.println("Record Inserted...."+s1);
out.println("Record Inserted...."+s2);
out.println("Record Inserted...."+s3);
ResultSet rs=st.executeQuery("insert into emaillists values("+s1+","+s2+","+s3+")");
out.println("Record Inserted....");
rs.close();
st.close();
cn.close();
}
catch(Exception e)
{
out.println(e.getMessage());
}
out.println("<P>&nbsp;</P></FONT></BODY></HTML>");
}
}

JDBC connectivity with MS access

import java.sql.*;
public class email
{
public static void main(String args[])
{
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection cn = DriverManager.getConnection("jdbc:odbc:emaildb", "admin", "");
Statement st = cn.createStatement();
ResultSet rs = st.executeQuery("select * from emaillists");
System.out.println("Name\tEmail\tSite\n");
while(rs.next())
{
System.out.print(rs.getString(1)+"\t");
System.out.print(rs.getString(2)+"\t");
System.out.print(rs.getString(3)+"\n");
}
rs.close();
st.close();
cn.close();
}
catch(Exception e)
{
System.out.print(e);
}
}
}

JSP with MSaccess Database

<%--
Document : File2
Created on : Nov 11, 2011, 3:00:10 PM
Author : Spectrum
--%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head><title>Enter to database</title></head>
<body>
<table>
<%@ page import="java.util.*" %>
<%@ page import="javax.sql.*;" %>
<%
java.sql.Connection con;
java.sql.Statement s;
java.sql.ResultSet rs;
java.sql.PreparedStatement pst;
con=null;
s=null;
pst=null;
rs=null;
 
// Remember to change the next line with your own environment
/*String url= "jdbc:jtds:sqlserver://nameofyourdatabaseserver.or.ipaddress/yourdatabasename";
String id= "username";
String pass = "password";*/
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con = java.sql.DriverManager.getConnection("jdbc:odbc:emaildb", "", "");
}
catch(ClassNotFoundException e)
{
e.printStackTrace();
}
String sql = "select * from emaillists";
try
{
s = con.createStatement();
rs = s.executeQuery(sql);
%>
<%while( rs.next() )
{
%>
<tr>
<td><%= rs.getString(1) %></td>
<td><%= rs.getString(2) %></td>
<td><%= rs.getString(3) %></td>
</tr>
<%
} %>
<%}
catch(Exception e)
{
e.printStackTrace();
}
finally
{
if(rs!=null) rs.close();
if(s!=null) s.close();
if(con!=null) con.close();
}
%>
</body>
</html>

Servlet Progming for JDBC

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.sql.*;
 
public class emaildb extends HttpServlet
{
Connection cn;
/*private ServletConfig config;
public void init(ServletConfig config) throws ServletException
{
this.config=config;
}*/
public void service (HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException
{
//HttpSession session = req.getSession(true);
res.setContentType("text/html");
PrintWriter out = res.getWriter();
out.println("<HTML><HEAD><TITLE>Emai List.</TITLE>");
out.println("</HEAD>");
out.println("<BODY bgColor=blanchedalmond text=#008000 topMargin=0>");
out.println("<P align=center><FONT face=Helvetica><FONT color=fuchsia style=\"BACKGROUND-COLOR: white\"><BIG><BIG>List of E-mail addresses.</BIG></BIG></FONT></P>");
out.println("<P align=center>");
out.println("<TABLE align=center border=1 cellPadding=1 cellSpacing=1 width=\"75%\">");
out.println("<TR>");
out.println("<TD>Name</TD>");
out.println("<TD>E-mail</TD>");
out.println("<TD>Website</TD></TR>");
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
cn = DriverManager.getConnection("jdbc:odbc:emaildb", "admin", "");
Statement st=cn.createStatement();
ResultSet rs=st.executeQuery("select * from emaillists");
while(rs.next())
{
out.println();
out.println("<TR>");
out.println("<TD>" + rs.getString(1) + "</TD>");
out.println("<TD>" + rs.getString(2) + "</TD>");
String s=rs.getString(3);
out.println("<TD><a href=" + s + ">" + s + "</a></TD>");
out.println("</TR>");
}
rs.close();
st.close();
cn.close();
}
catch(Exception e)
{
out.println(e.getMessage());
}
out.println("</TABLE></P>");
out.println("<P>&nbsp;</P></FONT></BODY></HTML>");
}
/*public void destroy()
{
}*/
}

Wednesday, November 9, 2011

Print USB printer From XP

In order to print from DOS in an offline environment like the stores, you will need to do a couple of things.

1)      Install the Microsoft Loopback Adapter
a)      In Control Panel, double click on Add Hardware.
b)      Click Next
c)      When the scan finishes, select "Yes, I have already connected the hardware"
d)     Click Next
e)      Scroll to the bottom of the list and select "Add a new hardware device"
Click Next
f)       Select "Install the hardware that I manually select from a list (Advanced)"
g)      Click Next
h)      Select "Network Adapters"
i)        Click Next
j)        Select "Microsoft" under the Manufacturer list.
k)      Select "Microsoft Loopback Adapter" in the Network Adapter list.
l)        Click Next
m)    Click Next
n)      Click Finish

2)      Configure the Adapter
a)      The loopback adapter is a virtual network adapter and can be configured the same as a regular network card.
b)      Set the adapter to have a static IP address such as 192.168.1.1/ 255.255.255.0

3)      Share the printer.
a)      I recommend you use a share name that you will remember.  I used “Printer” in the new machines that are already deployed.

4)      Capture the printer port.
a)      NET USE LPT1: \\[Computer Name]\Printer /PERSISTENT:YES
Now, not that I like to encourage this type of behaviour, but if you have done the above and still can't get it to print, you may find some help through one of the articles located here.

Uday Shah
9427439007

Thursday, November 3, 2011

what is IT

IT is Information Technology which is encourage to the people to develop something new.
Now a Days many student's want to become IT Professional.