J2SE help!


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 5 of 5

Thread: J2SE help!

  1. #1
    Join Date
    Jul 2006
    Posts
    2

    J2SE help!

    I require assistance on a college project in Java. This is the situation. A webpage has already been designed which consists of a dropdownlistbox that displays 100 Intervention Codes & Names along with two textboxes where the user can input two different values namely P & F. There are 25 different users that enter intervention related data. Each individual user is given a login & pwd with which he/she can login and input the values. Not all interventions are mandatory for each user. A report shall be generated using java code. It should contain intervention code, intervention name, p & f. If say for example, the user enters the data in July, the report should display P & F of upto May in the first column, then P & F of June in the second column and the sum of first & second columns in the third one. If the user doesn't input a value for any intervention, 0 shall be displayed. Please advise how to code. Thanks.

  2. #2
    Join Date
    Oct 2004
    Posts
    311
    and you really expect us to do your homework for you?

  3. #3
    Join Date
    Nov 2004
    Location
    Norway
    Posts
    1,560
    You should come up with at least an honest coding effort, a skeleton of a servlet of some sort.
    eschew obfuscation

  4. #4
    Join Date
    Jul 2006
    Posts
    2

    Post

    import java.io.*;
    import java.sql.*;
    public class Details1{
    public static void main(String args[]){
    Connection con=null;
    SelectDataApp1 s1=new SelectDataApp1();
    //int i=0;
    int p=s1.selectData();
    String a_code1[]=new String[p];
    String activity_name1[]=new String[p];
    float phy1[]=new float[p];
    float fin1[]=new float[p];
    SelectDataApp2 s2=new SelectDataApp2();
    String dcode="04";
    int q=s2.selectData(dcode);
    String a_code2[]=new String[q];
    float phy2[]=new float[q];
    float fin2[]=new float[q];
    try{
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    con=DriverManager.getConnection("jdbcdbc:funds","budget0607","budget0607");
    Statement st=con.createStatement();
    String sql2="select a_code,activity_name from activity order by 'a_code'";
    ResultSet rs=st.executeQuery(sql2);
    for(int i=0;rs.next();i++){
    //while(rs.next()){
    a_code1[i]=rs.getString("a_code");
    activity_name1[i]=rs.getString("activity_name");
    //System.out.println(a_code[i]);
    //System.out.println(activity_name[i]);
    //i++;
    }
    /*for(int i=0;i<p;i++){
    System.out.println(a_code[i]);
    System.out.println(activity_name[i]);
    }*/
    st.close();
    rs.close();
    System.in.read();
    }
    catch(IOException ioe){
    System.out.println(ioe.getMessage());
    }
    catch(SQLException sqle){
    System.out.println(sqle.getMessage());
    }
    catch(ClassNotFoundException cnfe){
    System.out.println(cnfe.getMessage());
    }
    catch(Exception e){
    System.out.println(e.getMessage());
    }
    finally{
    try{
    if(con!=null){
    con.close();
    }
    }
    catch(SQLException sqle){
    System.out.println(sqle.getMessage());
    }
    }

    try{
    //String dcode="11";
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    con=DriverManager.getConnection("jdbcdbc:funds","budget0607","budget0607");
    Statement st1=con.createStatement();
    String sql3="select a_code,sum(physical)phy,sum(financial)fin from expenditure where "+
    "dt_code='"+dcode+"' group by a_code";
    ResultSet rs1=st1.executeQuery(sql3);
    for(int i=0;rs1.next();i++){
    //while(rs1.next()){
    a_code2[i]=rs1.getString("a_code");
    phy2[i]=rs1.getFloat("phy");
    fin2[i]=rs1.getFloat("fin");
    //activity_name1[i]=rs1.getString("activity_name");
    //System.out.println(a_code2[i]);
    //System.out.println(phy2[i]);
    //System.out.println(fin2[i]);
    //i++;
    }
    /*for(int i=0;i<p;i++){
    System.out.println(a_code[i]);
    System.out.println(activity_name[i]);
    }*/
    st1.close();
    rs1.close();
    System.in.read();
    }
    catch(IOException ioe){
    System.out.println(ioe.getMessage());
    }
    catch(SQLException sqle){
    System.out.println(sqle.getMessage());
    }
    catch(ClassNotFoundException cnfe){
    System.out.println(cnfe.getMessage());
    }
    catch(Exception e){
    System.out.println(e.getMessage());
    }
    finally{
    try{
    if(con!=null){
    con.close();
    }
    }
    catch(SQLException sqle){
    System.out.println(sqle.getMessage());
    }
    }


    for(int i=0;i<p;i++){
    for(int j=0;j<q;j++){
    if(a_code1[i]!=a_code2[j]){
    System.out.println(a_code2[j]);
    System.out.println(phy2[j]);
    System.out.println(fin2[j]);
    }
    }
    System.out.println(a_code1[i]);
    System.out.println(phy1[i]);
    System.out.println(fin1[i]);
    break;
    }

    }
    }


    I wanted the last three lines within the loop but when that happens System.out.println(a_code2[j]);
    System.out.println(phy2[j]);
    System.out.println(fin2[j]);
    are getting looped which is unwanted. Please advise. Thanks.

  5. #5
    Join Date
    Nov 2004
    Location
    Norway
    Posts
    1,560

    String comparison.

    The statement
    Code:
    if (a_code1[a] != a_code2[b])
    compares the reference (address) of two strings, and that is (usually) true only for identical variables (i used a & b as arguments to avoid the italic formatting to click in....)
    Compiler optimization may sometimes put identical strings in the same memory space, but that is definitely not a feature to be utilized. Use the equals method (of Object) for string comparison, that way you compare the contents of the strings:
    Code:
    if (!a_code1[a].equals(a_code2[b]))
    BTW: you don't need to establish a new connection and create a new Statement each time you access the same database, unless there is different access privilidges to consider for the retriveal/update.
    Last edited by sjalle; 07-19-2006 at 09:46 AM.
    eschew obfuscation

Similar Threads

  1. Vote For JavaMail To Be Part Of J2SE
    By freesoft_2000 in forum Java
    Replies: 0
    Last Post: 10-22-2005, 05:23 PM
  2. Assert keyword in J2SE 1.4
    By Lori Piquet in forum Java
    Replies: 1
    Last Post: 03-12-2002, 03:10 PM
  3. J2SE v J2EE
    By Brett Hicking in forum Java
    Replies: 2
    Last Post: 12-04-2000, 08:35 AM
  4. Difference between J2SE and J2EE
    By srinivas ailani in forum Java
    Replies: 2
    Last Post: 10-17-2000, 02:08 AM
  5. J2SE or J2EE specs
    By Patrick Troughton in forum Java
    Replies: 2
    Last Post: 06-05-2000, 09:38 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center