IT Community - Software Programming, Web Development and Technical Support

User defined functions in Java

This is a discussion on User defined functions in Java within the Java Programming forums, part of the Software Development category; Hi, Can someone tell me how to create a simple user defined Java Class for calculating salary for employees every ...


Go Back   IT Community - Software Programming, Web Development and Technical Support > Software Development > Java Programming

Register FAQ Members List Calendar Mark Forums Read
  #1 (permalink)  
Old 08-20-2007, 09:00 AM
Murali Murali is offline
D-Web Master
 
Join Date: Feb 2007
Location: India-Chennai.
Posts: 386
Murali is on a distinguished road
Send a message via AIM to Murali
Default User defined functions in Java

Hi,

Can someone tell me how to create a simple user defined Java Class for calculating salary for employees every month based on the details available in the database?
__________________
-Murali..
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 09-14-2007, 04:57 AM
leoraja8 leoraja8 is offline
D-Web Sr.Programmer
 
Join Date: May 2007
Posts: 194
leoraja8 is on a distinguished road
Post Re: User defined functions in Java

here is one sample in which i used MsSqlserver database for Calculating Salary for employees................
PHP Code:

import java
.sql.*;
import javax.naming.*;
import javax.sql.DataSource;

public class 
Main 
{
    
    
/** Creates a new instance of Main */
    
public Main()
    {
        
    }
    
    
/**
     * @param args the command line arguments
     */
    
public static void main(String[] args
    {
         
        
Connection con null;
        
Statement st null;
        
PreparedStatement pt null;
        
CallableStatement ct null;
        try
        {
            
            Class.
forName("sun.jdbc.odbc.JdbcOdbcDriver");
            
con DriverManager.getConnection("jdbc:odbc:jspTest",  "sa",  "Pdindia123");
            
            
//Statement
            
st con.createStatement();
            
st.executeUpdate("insert into sample values('Jun', 3, 'Arun', 0, 34567)");
            
    
//Call Stored Procedure.    
            //CallableStatement(pname->procedure name ,  parameter)
//            ct = con.prepareCall("{call pname(1)}");
//            ct.execute();
//            
            //PreparedStatement
            
pt con.prepareStatement("select * from sample");
            
ResultSet rs pt.executeQuery();
            
            
System.out.println("Month\tNumber\tName\tLeave in days\tSalary");
            
System.out.println("------------------------------------------------------------");
            
            while(
rs.next())
            {
                
System.out.print("\t"+rs.getString("month")+"\n");
                
System.out.print("\t"+rs.getInt("num")+"\n");
                
System.out.print("\t"+rs.getString("nam")+"\n");
            
System.out.print("\t"+rs.getInt("leave")+"\n");
            
System.out.print("\t"+rs.getInt("sal")+"\n");
            }
            
System.out.println("----------------------------------------------------------------");
        }
        catch(
SQLException e)
        {
            
System.out.println(e.getMessage());
        }
        catch(
Exception  e)
        {
            
System.out.println(e.getMessage());
        }
    }    
}

Output:
---------

Month      Number    Name     Leave in days       Salary
----------------------------------------------------------------------------------
Jun          1              Smith          2            40234        
Jun          2                 Vimal         6             30094
Jun          3                 Arun          0             34567
---------------------------------------------------------------------------------- 

Last edited by leoraja8 : 09-14-2007 at 05:01 AM.
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 09-14-2007, 08:25 AM
saloni srivatsava saloni srivatsava is offline
D-Web Trainee
 
Join Date: Sep 2007
Posts: 16
saloni srivatsava is on a distinguished road
Default Re: User defined functions in Java

hi leoraja,
there was only one given in name field how you get those list of some other names....
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Implementation of user defined key class H2o Java Programming 1 08-08-2007 06:27 AM
What is a user defined exception? oxygen Java Programming 1 07-26-2007 04:58 AM
What are the primary considerations when implementing a user defined key? oxygen Java Programming 1 07-26-2007 04:52 AM
When providing a user defined key class for storing objects in the HashMaps or.... oxygen Java Programming 1 07-26-2007 04:51 AM
What is a user defined exception? theone Java Programming 1 07-24-2007 04:06 AM


All times are GMT -7. The time now is 11:02 PM.


Copyright ©2004 - 2007, DiscussWeb. All Rights Reserved.

SEO by vBSEO 3.0.0