TYBCA VI Slip Solution
TYBCA VI Slip Solution
import java.sql.*;
class Slip10
{
public static void main(String args[])
{
Connection con;
Statement stmt;
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con=DriverManager.getConnection("jdbc:odbc:dsn");
if(con==null)
{
System.out.println("Connection Failed.......");
System.exit(1);
}
System.out.println("Connection Established......");
stmt=con.createStatement();
ResultSet rs=stmt.executeQuery("select * from employee");
int cnt=0;
while(rs.next())
{
cnt++;
}
System.out.println("Number of records in Table are:"+cnt);
}
catch(Exception e)
{
System.out.println(e);
}
}
}
1.Write a JDBC program to delete the records of employees whose names are starting
with ‘A’ character. [15 Marks]
import java.sql.*;
import java.io.*;
class slip27_1
{
public static void main(String args[])
{
Connection con=null;
PreparedStatement pst=null;
int r=0,p=0;
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con=DriverManager.getConnection("Jdbc:Odbc:SUPRIYA");
pst=con.prepareStatement("delete * from Employee where Eno=?");
r=Integer.parseInt(args[0]);
pst.setInt(1,r);
pst.executeUpdate();
System.out.println("Record is deleted");
con.close();
pst.close();
}
catch(Exception e)
{
System.out.println(e);
}
}
}
2.Write a servlet program that provides information about a HTTP request from a client,such
as IP address and browser type. The servlet also provides information about the server on
which the servlet running ,such as the operating system type and the names of currently
loaded servlets.
[25 Marks]
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class InfoServlet1 extends HttpServlet
{
public void doGet(HttpServletRequest request,HttpServletResponse response) throws
ServletException,IOException
{
response.setContentType("text/html");
PrintWriter out=response.getWriter();
out.println("<html><body>");
out.println("Server Name="+request.getServerName());
out.println("Server Version="+request.getServerVersion());
out.println("Server Port="+request.getServerPort());
out.println("Server Name="+request.getLocalName());
out.println("</body></html>");
}
}
1.Write a JDBC Program in java to display the names of Employees starting with ‘S’
character.
import java.sql.*;
import java.io.*;
class slip21_1
{
public static void main(String args[])
{
Connection con=null;
Statement st=null;
ResultSet rs=null;
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con=DriverManager.getConnection("Jdbc:Odbc:SUPRIYA");
st=con.createStatement();
rs=st.executeQuery("select * from Employee where Ename like 'S%'");
while(rs.next())
{
System.out.println(rs.getInt(1)+"\t"+rs.getString(2)+"\t"+rs.getInt(3));
}
con.close();
st.close();
}
catch(Exception e)
{
System.out.println(e);
}
}
}
2. Write a java program to display the number’s between 1 to 100 continuously in a TextField
by clicking on button. (use Runnable Interface) [25 Marks]
import java.awt.event.*;
import javax.swing.*;
class Message implements Runnable
{
JTextField t;
public void run()
{
for(int i =1; i<=100;i++)
{
t.setText(""+i);
try
{
Thread.sleep(50);
}
catch(Exception e)
{
e.printStackTrace();
}
}
}
}
class Slip12_1 implements ActionListener
{
JFrame f;
JPanel p;
JTextField t;
JButton b;
Thread t1;
Slip12_1()
{
f = new JFrame();
p = new JPanel();
t = new JTextField(60);
b = new JButton("Start");
t1 = new Thread(this);
b.addActionListener(this);
p.add(t);
p.add(b);
f.add(p);
f.setSize(400, 400);
f.setVisible(true);
}
public void actionPerformed(ActionEvent e)
{
t1.start();
}
}
1.Write a java program to display name and priority of a Thread.
public class MainThread
{
public static void main(String arg[])
{
Thread t=Thread.currentThread();
System.out.println("Current Thread:"+t);
//Change Name t.setName("My Thread ");
System.out.println ("After the name is Changed:"+t);
try {
for(int i=2;i>0;i--)
{
System.out.println(i);
Thread.sleep(1000);
}
}
catch(Exception e)
{
System.out.println(e);
}
}
}