Data Connectivity

No Comment - Post a comment

/* Java Program that implements data connectivity */

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.sql.*;
public class Test extends JFrame implements ActionListener
{
Container con;
JLabel l1;
JLabel l2;
JLabel l3;
JLabel l4;
JLabel l5;
JTextField lt1;
JTextField lt2;
JTextField lt3;
JTextField lt4;
JTextField lt5;
JButton lb1;
Connection con1;
Statement s;
ResultSet rs;
public Test()
{
super("student details!!!");
con=getContentPane();
con.setLayout(null);
l1=new JLabel("Roll no.");
l1.setBounds(50,10,250,75);
con.add(l1);

l2=new JLabel("Name");
l2.setBounds(50,30,250,75);
con.add(l2);

l3=new JLabel("Age");
l3.setBounds(50,50,250,75);
con.add(l3);

l4=new JLabel("Address");
l4.setBounds(50,70,250,75);
con.add(l4);

l5=new JLabel("Marks");
l5.setBounds(50,90,250,75);
con.add(l5);

lt1=new JTextField(10);
lt1.setBounds(115,35,100,15);
con.add(lt1);

lt2=new JTextField(20);
lt2.setBounds(115,60,100,15);
con.add(lt2);

lt3=new JTextField(30);
lt3.setBounds(115,80,100,15);
con.add(lt3);

lt4=new JTextField(40);
lt4.setBounds(115,103,100,15);
con.add(lt4);

lt5=new JTextField(50);
lt5.setBounds(115,127,100,15);
con.add(lt5);

lb1=new JButton("GO");
lb1.setBounds(250,30,100,50);
con.add(lb1);

lb1.addActionListener(this);
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con1=DriverManager.getConnection("jdbc:odbc:mydsn","sa","");
s=con1.createStatement();
}
catch(SQLException e)
{
System.out.println(e.toString());
}
catch(ClassNotFoundException e)
{
System.out.println(e.toString());
}
}
public void actionPerformed(ActionEvent e)
{
/*int m=Integer.parseInt(lt1.getText());
String n=lt2.getText();
int o=Integer.parseInt(lt3.getText());
String p=lt4.getText();
int q=Integer.parseInt(lt5.getText());*/

String str="select *from student_det1 where roll_no='"+lt1.getText()+ "'";
System.out.println(str);
try
{
rs=s.executeQuery(str);
while(rs.next())
{
lt2.setText(rs.getString(2));
lt3.setText(rs.getString(3));
lt4.setText(rs.getString(4));
lt5.setText(rs.getString(5));
}
}
catch(SQLException ee)
{
System.out.println(ee.toString());
}
}
public static void main(String args[])
{
Test t=new Test();
t.setSize(500,600);
t.setVisible(true);
}
}

 

Blogsvertise

2 comments - Post a comment

Blogsvertise is set up for bloggers to earn revenue from their blogs. Firstly you need to submit your blog to them for approval and once your blog is approved it goes into assignment queue, then the Blogsvertise administrator assigns tasks ( writing posts) for what their advertisers want you to mention in your blog. You dont have to endorse the website product/service, just mention it in your blog and add 3 links to the advertiser website in your entry.
For each post you are paid anywhere in between $4 - $25 depending upon the size and the popularity of your blog. Later you will be paid more depending on the quality of your posts and traffic.

 

The Life Cycle of an Applet

No Comment - Post a comment

The Life Cycle of an Applet :

Loading the Applet

When an applet is loaded, here's what happens:

* An instance of the applet's controlling class (an Applet subclass) is created.
* The applet initializes itself.
* The applet starts running.


Leaving and Returning to the Applet's Page

When the user leaves the page -- for example, to go to another page -- the applet has the option of stopping itself. When the user returns to the page, the applet can start itself again. The same sequence occurs when the user iconifies and then reopens the window that contains the applet. (Other terms used instead of iconify are minaturize, minimize, and close.)

Reloading the Applet
Some browsers let the user reload applets, which consists of unloading the applet and then loading it again. Before an applet is unloaded, it's given the chance to stop itself and then to perform a final cleanup, so that the applet can release any resources it holds. After that, the applet is unloaded and then loaded again.

Quitting the Browser

When the user quits the browser (or whatever application is displaying the applet), the applet has the chance to stop itself and do final cleanup before the browser exits.
Summary
An applet can react to major events in the following ways:
1. It can initialize itself.
2. It can start running.
3. It can stop running.
4. It can perform a final cleanup, in preparation for being unloaded.

 

Properties Of URL

1 comments - Post a comment

import java.net.*;

class Gotest
{
public static void main(String agrs[]) throws MalformedURLException
{
URL hp = new URL("http://www.javapgms.blogspot.com/Array.html");
System.out.println("Protocol : " +hp.getProtocol());
System.out.println("Port : " +hp.getHost());
System.out.println("Host : " + hp.getHost());
System.out.println("File : " +hp.getFile());
}
}

/*

getProtocol() : Returns the protocal identifier of the given URL object.
getPort() : Returns the integer value of the port number of the URL Object. If the port is not set the it returns -1.
getHost() : Returns The Host Name.
getFile() : Returns The file Name.
getRef() : Returns The reference component

 

Fetch Url Of A Site

No Comment - Post a comment

/* Java Program To Fetch The Url Of Any Site */

import java.io.*;
import java.net.*;

public class fetchUrl
{
public static void main(String args[])
{
try
{
if(args.length !=1)
{
System.out.println("Usage: java fetchUrl < URL such as http://www.javapgms.blogspot.com>");
System.exit(0);
}
System.out.println("Hello");
URL url = new URL (args[0]);
System.out.println("\n Fetching URL :" +args[0] +"\n");
BufferedReader br = new BufferedReader(new InputStreamReader(url.openStream()));
String strline;
while((strline = br.readLine())!=null)
{
System.out.println(strline);
}
br.close();
}
catch(MalformedURLException mue)
{
System.out.println("Unknown URL");
}

catch(IOException ioe)
{
System.out.println("IO Error");
}
}
}