Wednesday, 24 January 2018

Advancedjava-Slip17



Slip17
Q1.  Write a java program which will display name and priority of current thread. Change name of Thread to MyThread and priority to 2. Display the details of Thread.        

import java.awt.*;
import java.awt.event.*;
import java.util.*;
import java.io.*;

class Ex1
{

public static void main(String args[])
{
Thread t=Thread.currentThread();
System.out.println("ThreadName:"+t.getName());
System.out.println("Priority:"+t.getPriority());
t.setName("mythread");
t.setPriority(2);
System.out.println("nOW ThreadName:"+t.getName());
System.out.println("Priority:"+t.getPriority());

}
}                                                                                                                                                                                 
Q2.  Write a JDBC application using swing for the following:

Type DDL Query
       
                                                                                                                                                    



Create Table
Drop Table
Alter Table
 


import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.sql.*;

class DDLOperations extends JFrame{
            private JPanel panNorth,panSouth;
            private JLabel lblQuery;
            private JTextArea txtQuery;
            private JButton btnCreate,btnAlter,btnDrop;

            public DDLOperations(){
                        lblQuery = new JLabel("Type DDL Query");
                        txtQuery = new JTextArea(4,50);
                       
                        panNorth = new JPanel();
                        panNorth.add(lblQuery);
                        panNorth.add(new JScrollPane(txtQuery));

                        btnCreate = new JButton("Create Table");
                        btnAlter = new JButton("Alter Table");
                        btnDrop = new JButton("Drop Table");

                        panSouth = new JPanel();
                        panSouth.add(btnCreate);
                        panSouth.add(btnAlter);
                        panSouth.add(btnDrop);

                        setTitle("DDL Operations");
                        setSize(400,300);
                        add(panNorth,"North");
                        add(panSouth,"South");
                        setVisible(true);
                        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

                        ButtonHandler bh = new ButtonHandler();
                        btnCreate.addActionListener(bh);
                        btnAlter.addActionListener(bh);
                        btnDrop.addActionListener(bh);
            }

            class ButtonHandler implements ActionListener{
                        public void actionPerformed(ActionEvent ae){
                                    try{
                                                Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
               con=DriverManager.getConnection("jdbc:odbc:lab.dsn");
                                   
                                                String sql = txtQuery.getText();
                                                Statement s = con.createStatement();
                                                s.execute(sql);
                                                txtQuery.setText("");
                                    }
                                    catch(Exception e){
                                                JOptionPane.showMessageDialog(null,e);
                                    }
                        }
            }

            public static void main(String args[]){
                        new DDLOperations();
            }
}