-
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.
-
and you really expect us to do your homework for you?
-
You should come up with at least an honest coding effort, a skeleton of a servlet of some sort.
eschew obfuscation
-
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("jdbc dbc: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("jdbc dbc: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.
-
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
-
By freesoft_2000 in forum Java
Replies: 0
Last Post: 10-22-2005, 05:23 PM
-
By Lori Piquet in forum Java
Replies: 1
Last Post: 03-12-2002, 03:10 PM
-
By Brett Hicking in forum Java
Replies: 2
Last Post: 12-04-2000, 08:35 AM
-
By srinivas ailani in forum Java
Replies: 2
Last Post: 10-17-2000, 02:08 AM
-
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
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks