Savitribai Phule Pune University T.Y.B.B.A.(C.A.) Advanced Java Practical Slip 19 Answers

 



A) Write a JSP program which accept UserName in a TextBox and greets the user

according to the time on server machine.

Answer :

File : Slip19A.jsp

<%

 

String name=request.getParameter("username");

java.util.Date d=new java.util.Date();

int hr=d.getHours();

 

if(hr<12) {

    out.println("Good Morning : "+name);

}  

if(hr>12 && hr<16)

{

    out.println(" Good Afternoon : "+name);

}

if(hr>16)

{

    out.println(" Good Evening:"+name);

}

 %>

 

File : Slip19A.html

 

<html>

 

<body>

    <form action="http://localhost:8080/jsp/Slip19A/Slip19A.jsp" method="post">

        <input type="text" name="username">

        <input type="submit">

    </form>

</body>

 

</html>


B) Write a Java program to display first record from student table (rno, sname, per)

onto the TextFields by clicking on button. (Assume Student table is already created).

Answer :

import java.sql.*;

import java.awt.*;

import java.awt.event.*;

import javax.swing.*;

 

public class Slip4B extends JFrame implements ActionListener {

 

    JButton jb;

    JTextField t1, t2, t3;

    Container c;

 

    Connection con;

    Statement st;

    ResultSet rs;

 

    public Slip4B() {

 

        c = getContentPane();

        c.setLayout(null);

 

        t1 = new JTextField();

        t1.setFont(new Font("Arial", Font.PLAIN, 20));

        t1.setSize(200, 30);

        t1.setLocation(100, 50);

        c.add(t1);

 

        t2 = new JTextField();

        t2.setFont(new Font("Arial", Font.PLAIN, 20));

        t2.setSize(200, 30);

        t2.setLocation(100, 100);

        c.add(t2);

 

        t3 = new JTextField();

        t3.setFont(new Font("Arial", Font.PLAIN, 20));

        t3.setSize(200, 30);

        t3.setLocation(100, 150);

        c.add(t3);

 

        jb = new JButton(">> DISPLAY FIRST RECORD<<");

        jb.setFont(new Font("Arial", Font.PLAIN, 20));

        jb.setSize(200, 30);

        jb.addActionListener(this);

        jb.setLocation(100, 200);

        c.add(jb);

 

        setVisible(true);

        setSize(800, 500);

 

    }

 

    public void actionPerformed(ActionEvent aq) {

 

        try {

            Class.forName("com.mysql.jdbc.Driver");

            con = DriverManager.getConnection("jdbc:mysql://localhost:3306/Server", "root", "12345");

 

            if (aq.getSource() == jb) {

                st = con.createStatement(rs.TYPE_SCROLL_SENSITIVE, rs.CONCUR_READ_ONLY);

 

                rs = st.executeQuery("Select * from Student;");

                rs.first();

                t1.setText(Integer.toString(rs.getInt(1)));

                t2.setText(rs.getString(2));

                t3.setText(Integer.toString(rs.getInt(3)));

            }

            con.close();

        } catch (Exception ex) {

        }

 

    }

 

    public static void main(String args[]) throws Exception {

 

        new Slip4B();

 

    }

 

}

Savitribai Phule Pune University T.Y.B.B.A.(C.A.) Advanced Java Practical Slip 19 Answers Savitribai Phule Pune University T.Y.B.B.A.(C.A.) Advanced Java Practical Slip 19 Answers Reviewed by technical_saurabh on December 15, 2022 Rating: 5

No comments:

Powered by Blogger.