Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: Java HTML SQL Applet
import java.sql.*;
import java.applet.*;
import java.awt.*;	
import java.awt.event.*;
import java.io.*;	
			
 
/*
<HTML>
<BODY>
<HEAD>
<applet code="Sem3ResultsApplet" width=1000 height=1000>
</applet>
</HEAD>
</BODY>
br mode="hold" />*/
 

public class Sem3ResultsApplet extends Applet implements ItemListener,ActionListener,MouseListener
{
    Label LIDNo;
    TextField IDNo;
    Button GO;
 
    String  Name;
    int     ENGLISH;
    int     IILANG;
    int     MATHEMATICS;
    int     STATISTIC;
    int     COMPUTERSCIENCE;
    int     MATHEMATICSPR;
    int     STATISTICSPR;
    int     COMPUTERSCIENCEPR;
    int     TOTAL;
    int     TPOSITION;
    int     GrandTOTAL;
    int     GPOSITION;
    float   PERCENTAGE;
 
    public void init() 
    {	
	// LABEL
	LIDNo = new Label("Enter Your IDNo :",Label.LEFT);
	//TEXT FIELD
	IDNo  = new TextField(8);
	// BUTTON
	GO = new Button("GO");
 
	// Adding items
	add(LIDNo);
	add(IDNo);
	add(GO);
 
	// Adding Listeners
	IDNo.addActionListener(this);
	GO.addActionListener(this);
	addMouseListener(this);
    }
 
    // Provide empty implementations for the other MouseListener methods.
    public void mouseClicked(MouseEvent me) {
    }
 
    public void mouseEntered(MouseEvent me) {
    }
 
    public void mouseExited(MouseEvent me) {
    }
 
    public void mouseReleased(MouseEvent me) {
    }
 
    public void mousePressed(MouseEvent me) {
    }
 
    public void actionPerformed(ActionEvent ae)
    {
        String str = ae.getActionCommand();
        if (ae.getSource() == GO)
        {
            try
            {
                Connection conn = DriverManager.getConnection("jdbc:odbc:FirstData"); 
                Statement stmt = conn.createStatement();
                String strSelect = "select * from Sem3Results where IDNo ="+IDNo.getText();
                ResultSet rset   = stmt.executeQuery(strSelect);
                while(rset.next())
                {
                    int IDNo = rset.getInt("IDNo");
                    String Name = rset.getString("Name");
                    int ENGLISH = rset.getInt("ENGLISH");
                    int IILANG = rset.getInt("IILANG");
                    int MATHEMATICS = rset.getInt("MATHEMATICS");
                    int STATISTIC = rset.getInt("STATISTIC");
                    int COMPUTERSCIENCE = rset.getInt("COMPUTERSCIENCE");
                    int MATHEMATICSPR = rset.getInt("MATHEMATICSPR");
                    int STATISTICSPR = rset.getInt("STATISTICSPR");
                    int COMPUTERSCIENCEPR = rset.getInt("COMPUTERSCIENCEPR");
                    int TOTAL = rset.getInt("TOTAL");
                    int TPOSITION = rset.getInt("TPOSITION");
                    int GrandTOTAL = rset.getInt("GrandTOTAL");
                    int GPOSITION = rset.getInt("GPOSITION");
                    float  PERCENTAGE = rset.getFloat("PERCENTAGE");	
                    break;
                }
                repaint();
            }
            catch(SQLException e) 
            {
                e.printStackTrace();
            }
        }
    }
 
    public void itemStateChanged(ItemEvent ie) {
        repaint();
    }
 
    public void paint(Graphics g) 
    {
        g.drawString("IDNo		:12141146"+IDNo.getText(),100,100);
        g.drawString("Name    		:"+Name,100,120);
        g.drawString("ENGLISH   	:"+ENGLISH,100,140);
        g.drawString("IILANG 		:"+IILANG,100,160);
        g.drawString("MATHEMATICS	:"+MATHEMATICS,100,180);
        g.drawString("STATISTICS	:"+STATISTIC,100,200);
        g.drawString("COMPUTERSCIENCE	:"+COMPUTERSCIENCE,100,220);
        g.drawString("MATHEMATICSPR	:"+MATHEMATICSPR,100,240);
        g.drawString("STATISTICSPR	:"+STATISTICSPR,100,260);
        g.drawString("COMPUTERSCIENCEPR	:"+COMPUTERSCIENCEPR,100,280);
        g.drawString("TOTAL		:"+TOTAL,100,300);
        g.drawString("TPOSITION		:"+TPOSITION,100,320);
        g.drawString("GrandTOTAL	:"+GrandTOTAL,100,340);
        g.drawString("GPOSITION		:"+GPOSITION,100,360);
        g.drawString("PERCENTAGE	:"+PERCENTAGE,100,380);
    }
}
Posted 21-May-13 0:56am
Edited 21-May-13 1:05am
v2
Comments
Prasad Khandekar at 21-May-13 6:08am
   
The applet is not able to locate the data source. Please use correct syntax. The DataSource firstData will not be present on the machine on which applet is going to run. Have a look at this link to find the correct syntax (http://www.connectionstrings.com/sql-server#microsoft-sql-server-odbc-driver).
 
Regards,

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Thank you Prasad Khandekar
 

Connection path is correct.
because when I used with main class it able to show output and it able to retrieve data.
It is not working with applet which does not retrieving data from sql database
the code is below
 

//sampel java prg to display record from the database "Students" using mysql- table(s) name: "Sem3Results"
 
import java.sql.*; // 1
import java.io.BufferedReader; // 2
import java.io.IOException; // 3
import java.io.InputStreamReader; // 4
// 5
public class Sem3Results // 6
{ // 7
// 8
public static void main(String[] args) // 9
{ // 10
// 11
System.out.println("Enter Your IDNo"); // 12
try // 13
{ // 14
// 15
BufferedReader bufferRead = new BufferedReader(new InputStreamReader(System.in)); // 16
String s = bufferRead.readLine(); // 17
Connection conn = DriverManager.getConnection("jdbc:odbc:FirstData"); // 18
Statement stmt = conn.createStatement(); // 19
String strSelect = "select * from Sem3Results where IDNo ="+s; // 20
// 22
// 23
ResultSet rset = stmt.executeQuery(strSelect); // 24
// 25
// 26
// 27
while(rset.next()) // 28
{ // 29
// 30
int IDNo= rset.getInt("IDNo"); // 31
String Name= rset.getString("Name"); // 32
int ENGLISH= rset.getInt("ENGLISH"); // 33
int IILANG= rset.getInt("IILANG"); // 34
int MATHEMATICS= rset.getInt("MATHEMATICS"); // 35
int STATISTIC= rset.getInt("STATISTIC"); // 36
int COMPUTERSCIENCE= rset.getInt("COMPUTERSCIENCE"); // 37
int MATHEMATICSPR= rset.getInt("MATHEMATICSPR"); // 38
int STATISTICSPR= rset.getInt("STATISTICSPR"); // 39
int COMPUTERSCIENCEPR= rset.getInt("COMPUTERSCIENCEPR"); // 40
int TOTAL= rset.getInt("TOTAL"); // 41
int TPOSITION= rset.getInt("TPOSITION"); // 42
int GrandTOTAL= rset.getInt("GrandTOTAL"); // 43
int GPOSITION= rset.getInt("GPOSITION"); // 44
float PERCENTAGE = rset.getFloat("PERCENTAGE"); // 45
// 46
System.out.println("IDNo :12141146"+IDNo); // 47
System.out.println("Name :"+Name); // 48
System.out.println("English :" + ENGLISH); // 49
System.out.println("II Language :" + IILANG); // 50
System.out.println("Mathematics :" + MATHEMATICS); // 51
System.out.println("Statistics :"+ STATISTIC); // 52
System.out.println("Computer Science :"+COMPUTERSCIENCE); // 53
System.out.println("Mathematics PR :"+MATHEMATICSPR); // 54
System.out.println("Statistics PR :"+STATISTICSPR); // 55
System.out.println("Computer Science PR :"+COMPUTERSCIENCEPR); // 56
System.out.println("Total :"+TOTAL); // 57
System.out.println("Rank :"+TPOSITION); // 58
System.out.println("Grand Total :"+GrandTOTAL); // 59
System.out.println("Rank :"+GPOSITION); // 60
System.out.println("Percentage :"+PERCENTAGE); // 61
break; // 62
} // 63
// 64
// 65
} // 66
catch(SQLException e) // 67
{ // 68
e.printStackTrace(); // 69
} // 70
catch(IOException e) // 71
{ // 72
e.printStackTrace(); // 73
} // 74
} // 75
} // 76
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 304
1 Sergey Alexandrovich Kryukov 255
2 Shweta N Mishra 216
3 Maciej Los 210
4 PIEBALDconsult 184
0 OriginalGriff 7,630
1 Sergey Alexandrovich Kryukov 7,022
2 DamithSL 5,586
3 Manas Bhardwaj 4,946
4 Maciej Los 4,525


Advertise | Privacy | Mobile
Web02 | 2.8.1411023.1 | Last Updated 21 May 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100