Year 2017
Group B
2.Write a program to display records from the table “employee” that contains (id, name, post and salary) inside the database “testdb”.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
import java.sql.*; public class Ques2_2017 { public static void main(String[] args) { String url = "jdbc:mysql://localhost:3306/testdb"; String uname = "root"; String pwd = ""; try { Class.forName("com.mysql.jdbc.Driver"); Connection con = DriverManager.getConnection(url, uname, pwd); String sql = "select * from employee"; Statement st = con.createStatement(); ResultSet rs = st.executeQuery(sql); while(rs.next()) { System.out.println(rs.getString("id")); System.out.println(rs.getString("name")); System.out.println(rs.getString("post")); System.out.println(rs.getString("salary")); } }catch(Exception ex) { System.out.println(ex); } } } |
Q.no 3 Create jsp page to display all odd numbers from 10 to 50
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
<%@page contentType="text/html" pageEncoding="UTF-8"%> <!DOCTYPE html> <html> <head> <title>Printing odd numbers from 10 to 50</title> </head> <body> <% out.print("<b> odd numbers from 10 to 50</><br>"); for( int i=10;i<=50;i++) { if(i%2!==0){ out.print("<br><b>"+i+"</b>"); } } %> </body> </html> |
Q.no 5 Write a servlet to find the reverse of a string.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
import java.applet.*; import java.awt.event.*; import java.awt.*; public class T2017_5 extends Applet implements ActionListener{ Panel p1,p2; Label l1,l2,l3; TextField t1,t2,t3; Button b1,b2; public void init(){ p1=new Panel(); p2=new Panel(); p1.setLayout(new GridLayout(3,2)); p2.setLayout(new FlowLayout()); l1=new Label("Number 1"); l2=new Label("Number 2"); l3=new Label("Result"); t1=new TextField(); t2=new TextField(); t3=new TextField(); t3.setEditable(false); p1.add(l1); p1.add(t1); p1.add(l2); p1.add(t2); p1.add(l3); p1.add(t3); add(p1); add(p2); b1=new Button("+"); b2=new Button("-"); p2.add(b1); p2.add(b2); } public void start(){ b1.addActionListener(this); b2.addActionListener(this); } public void actionPerformed(ActionEvent e){ int a=Integer.parseInt(t1.getText()); int b=Integer.parseInt(t2.getText()); if(e.getSource()==b1){ int c=a+b; t3.setText(" "+c); } else if(e.getSource()==b2){ int c=a-b; t3.setText(" "+c); } } } |
Group C
Q.no 7 Create a swing GUI that contains a combo box and a text field. When the user selects any item in the combo box, it should be displayed in the text field.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
import javax.swing.*; import javax.swing.event.*; import java.awt.*; import java.awt.event.*; public class T2017_6 extends JFrame{ TextField t1; JComboBox<String> combo; String[] s={"BIM","BHM","BSc. CSIT","BBM","BCA"}; public T2017_6(){ t1=new TextField(); t1.setEditable(false); combo=new JComboBox<String>(s); add(combo); add(t1); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); combo.addItemListener(new ItemListener(){ public void itemStateChanged(ItemEvent e){ t1.setText(""+combo.getSelectedItem()); } }); setLayout(new GridLayout(2,1)); setSize(100,100); setVisible(true); } public static void main(String[] args) { new T2017_6(); } } |