Ecj_file

download Ecj_file

of 6

Transcript of Ecj_file

  • 7/27/2019 Ecj_file

    1/6

    INDEX

    SN. Program Date Signature1. Write a program to copy the content of one file to another.

    2. Write a program to display record of a table product_id,product_name, product_catogries, product_price in a GUI.

    3. Servlet programming

    4. MultiThreading Program

  • 7/27/2019 Ecj_file

    2/6

    Que1:-

    /* @author BOSS

    */

    import java.io.*;

    public class File_copy

    {

    public static void main(String[] arg) throws FileNotFoundException, IOException

    {

    FileInputStream dis;

    FileOutputStream dos;

    File f=new File("first.txt");

    File f1=new File("second.txt");

    dos=new FileOutputStream(f);

    dis=new FileInputStream(f);

    String str="this is a test file";

    byte b = 0;

    dos.write(str.getBytes());

    dos.close();

    dos=new FileOutputStream(f1);

    try

    {

    while((b=(byte)dis.read())!=-1)

    { dos.write(b);

    }

    }

    catch(FileNotFoundException e)

    {

    System.out.println("file not found");

    }

    dis.close();

    dos.close();

    }

    }

    Que2:-/*

    * @author Sachin

    */

    import java.sql.*;

    import java.util.*;

    import java.awt.*;

    import java.applet.*;

    import java.awt.event.*;

  • 7/27/2019 Ecj_file

    3/6

    import java.util.logging.Level;

    import java.util.logging.Logger;

    public class Connection_Demo extends Applet implements ActionListener

    {

    TextField tp_id,tp_name,tp_cat,tp_price;

    Label lp_id,lp_name,lp_cat,lp_price;

    Button bt;public void init()

    {

    tp_id= new TextField();

    lp_id=new Label("product_id");

    add(lp_id);

    add(tp_id);

    tp_name= new TextField();

    lp_name=new Label("product_name");

    add(lp_name);

    add(tp_name);

    tp_cat= new TextField();

    lp_cat=new Label("product_categories");

    add(lp_cat);

    add(tp_cat);

    tp_price= new TextField();

    lp_price=new Label("product_price");

    add(lp_price);

    add(tp_price);

    bt=new Button("show");

    add(bt);

    bt.addActionListener(this);

    }

    public void actionPerformed(ActionEvent e){

    Connection conn;

    Statement stmt;

    int id,p_price;

    String p_id,p_cat,p_name;

    try

    {

    Class.forName("org.apache.derby.jdbc.ClientDriver") ;

    conn=DriverManager.getConnection("jdbc:derby://localhost:1527/Sachin","sachin","sachin");

    stmt=conn.createStatement();

    ResultSet rs = rs=stmt.executeQuery("select * from app.PRODUCT");

    while(rs.next()){

    id=rs.getInt(1);

    p_name=new String(rs.getString(2));

    p_cat=new String(rs.getString(3));

    p_price=rs.getInt(4);

    tp_id.setText("id");

    tp_name.setText(p_name);

    tp_cat.setText(p_cat);

  • 7/27/2019 Ecj_file

    4/6

    }

    } catch (SQLException ex) {

    Logger.getLogger(Connection_Demo.class.getName()).log(Level.SEVERE, null, ex);

    }

    catch (ClassNotFoundException ex) {

    Logger.getLogger(Connection_Demo.class.getName()).log(Level.SEVERE, null, ex);

    }

    }

    }

    Q3:-Servlet Program

    Config file---

    TestServlet

    TestServlet

    TestServlet

    /test

  • 7/27/2019 Ecj_file

    5/6

    Java file:---

    import java.io.*;

    import javax.servlet.*;

    import javax.servlet.http.*;

    public class TestServlet extends HttpServlet {

    public void doGet(HttpServletRequest request, HttpServletResponse response) throws

    IOException, ServletException {

    response.setContentType("text/html");

    PrintWriter out = response.getWriter();

    out.println("hello world");

    }

    public void doPost(HttpServletRequest request, HttpServletResponse response) throws

    IOException, ServletException {

    doGet(request, response);

    }

    }

    Q4. Threading program

    //C:\java

    class t1 extends Thread

    {

    public void run()

    {

    for(int i=0;i

  • 7/27/2019 Ecj_file

    6/6

    class t2 extends Thread

    {

    public void run()

    {

    for(int j=0;j