R
rmannam
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.
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=rs.getString("a_code");
activity_name1=rs.getString("activity_name");
//System.out.println(a_code);
//System.out.println(activity_name);
//i++;
}
/*for(int i=0;i<p;i++){
System.out.println(a_code);
System.out.println(activity_name);
}*/
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=rs1.getString("a_code");
phy2=rs1.getFloat("phy");
fin2=rs1.getFloat("fin");
//activity_name1=rs1.getString("activity_name");
//System.out.println(a_code2);
//System.out.println(phy2);
//System.out.println(fin2);
//i++;
}
/*for(int i=0;i<p;i++){
System.out.println(a_code);
System.out.println(activity_name);
}*/
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!=a_code2[j]){
System.out.println(a_code2[j]);
System.out.println(phy2[j]);
System.out.println(fin2[j]);
}
}
System.out.println(a_code1);
System.out.println(phy1);
System.out.println(fin1);
break;
}
}
}
I want the bottom 3 lines to be looped but when I do so,
System.out.println(a_code2[j]);
System.out.println(phy2[j]);
System.out.println(fin2[j]);
are getting in the loop, which is unwanted. Please advise on an
efficient way to code. Thanks.
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.
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=rs.getString("a_code");
activity_name1=rs.getString("activity_name");
//System.out.println(a_code);
//System.out.println(activity_name);
//i++;
}
/*for(int i=0;i<p;i++){
System.out.println(a_code);
System.out.println(activity_name);
}*/
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=rs1.getString("a_code");
phy2=rs1.getFloat("phy");
fin2=rs1.getFloat("fin");
//activity_name1=rs1.getString("activity_name");
//System.out.println(a_code2);
//System.out.println(phy2);
//System.out.println(fin2);
//i++;
}
/*for(int i=0;i<p;i++){
System.out.println(a_code);
System.out.println(activity_name);
}*/
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!=a_code2[j]){
System.out.println(a_code2[j]);
System.out.println(phy2[j]);
System.out.println(fin2[j]);
}
}
System.out.println(a_code1);
System.out.println(phy1);
System.out.println(fin1);
break;
}
}
}
I want the bottom 3 lines to be looped but when I do so,
System.out.println(a_code2[j]);
System.out.println(phy2[j]);
System.out.println(fin2[j]);
are getting in the loop, which is unwanted. Please advise on an
efficient way to code. Thanks.