rahul kumar

Ranch Hand
+ Follow
since Feb 24, 2001
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
In last 30 days
0
Forums and Threads

Recent posts by rahul kumar

i was discussing this problem with some of my friends , which is a result of a statement made by my teacher she says that java programs are 80% compiled and 20% interpreted. i was confused that if we have already compiled the java source code that what is the use of interpretation who does interpretation of byte code made by jvm diffrenet means it agains generate some other machine code. pls explain.
also pls explain , i read this in Complete Reference Java2 byt patrick naughton and Herbert schildts that 'implementation of jvm is different on different machines thats why we don't compile the bytecode rather we interpret it' this line is taken from the above mentioned book on page 11 para 2 under heading "Java's Magic: The ByteCode"
22 years ago
Pls guys reply soon ,don't get afraid of the size of code pls read it, it is really very simple and do reply soon as i am running out of time.
22 years ago
let me give u a brief description of what i am doing and what i want.
i am creating a html page through my program and then setting the page of JEditorPane to the html page created. this all thing occurs on the actionevent of a ComboBox.
What i have done...
on the ActionEvent of JComboBox i check which item was selected and then
1. i call a method user made create_report(int)
the int argument is the current selected item of the combobox, this int argument decides different set of coding in the html page.
In the create_report method i create a FileWriter and then write the code in the file. then closes the Filewriter object.Now one thing important that every time the create_report() method is called the previous html file is replaced by the new file as per the FileWriter's constructor bhehaviour.
2.in next step i create a URL object to that file
3.in the 3rd and the last step i call the setPage method of JEditorPane and pass the URL.
Now what the problem is the JEditor only shows the first html page created but not the next and onwards but when i check the html file in the browser the contents have correctly changed according to the JCombobox selection being made.
I am unable to understand why this is happening.

Code.....
//////////////////////////////////////////////
these three if constructs are inside the actionPerformed method
if(report.getSelectedIndex()==0)
{
try
{
create_report(0);
URL location=new URL("file:Report.html");
//report_pane.setText("");
System.out.println(report_pane.getPage());
report_pane.setPage(location);
parent.doLayout();
}
catch(Exception e)
{
System.out.println("Exception in(report, if report.getSelectedindex) :"+e);
}
}
*******************
if(report.getSelectedIndex()==1)
{
try
{
create_report(1);
URL location=new URL("file:Report.html");
//report_pane.setText("");
System.out.println(report_pane.getPage());
report_pane.setPage(location);
parent.doLayout();
}
catch(Exception e)
{
System.out.println("Exception in(report, if report.getSelectedindex) :"+e);
}
}
******************************
if(report.getSelectedIndex()==2)
{
try
{
create_report(2);
URL location=new URL("file:Report.html");
//report_pane.setText("");
System.out.println(report_pane.getPage());
report_pane.setPage(location);
parent.doLayout();
}
catch(Exception e)
{
System.out.println("Exception in(report, if report.getSelectedindex) :"+e);
}
}

*************************
create_report() method....
private void create_report(int index)throws Exception
{
FileWriter fw=new FileWriter("Report.html");
fw.write("<html>");
fw.write("<body>");

if(index==0)
{
fw.write("<font color=blue ><b><center> TOTAL NUMBER OF COMPLAINTS & AMOUNT GENERATED </center></b></font>");
}
if(index==1)
{
fw.write("<font color=blue ><b><center> TOTAL NOUMBER OF COMPLAINTS HANDLED BY THE EMPLOYEE </center></b></font>");
}
if(index==2)
{
fw.write("<font color=blue ><b><center> TOTAL NUMBER OF COMPLAINTS MADE BY CLIENTS </center></b></font>");
}

fw.write("</body>");
fw.write("</html>");
fw.close();
}
//////////////////////////////////////////////
22 years ago
i am trying this code pls correct it.but it gives this Exception and output
Output......
///////////////////////////////////////////////
text/plain
text/html
Exception in thread "main" java.net.MalformedURLException: no protocol: <html><b
ody><h1>W O W !.............</h1></body></html>
at java.net.URL.<init>(URL.java:579)
at java.net.URL.<init>(URL.java:476)
at java.net.URL.<init>(URL.java:425)
at javax.swing.JEditorPane.setPage(JEditorPane.java:774)
at JEditorPaneDemo.main(JEditorPaneDemo.java:17)
///////////////////////////////////////////////

Code....
///////////////////////////////////////////////
import javax.swing.*;
class JEditorPaneDemo
{
public static void main(String args[]) throws Exception
{
JFrame frm=new JFrame("EditorPane");
JEditorPane jdp=new JEditorPane();
String data="<html><body><h1>W O W !.............</h1></body></html>";
System.out.println(jdp.getContentType());
jdp.setContentType("text/html");
System.out.println(jdp.getContentType());
jdp.setPage(data);
frm.getContentPane().add(jdp);
frm.pack();
frm.setVisible(true);
}
}
///////////////////////////////////////////////
22 years ago
I have some data which is actually a complaint description for computer. now the description on an average is 3-4 lines long apprx(50-60 words). It has to be shown in the Column , but it is very odd for the user to increase the size of the column to see the complete text, so tell me how can i wrap the text in the preferred size of the column.
Pls reply soon as i am running out of time , as my project's deadline is 25 march.
22 years ago
Jamie u again answered what i do not want. i want SQLException: Funtion Sequence error.Pls read the code which i have given in the reply i have also given the briefing of the code so that u can better understand it.
thanks guys for ur reply but u misunderstood my problem. the problem udescribed and told the solution of was also faced by me i was resolved a week before in the way David told with the same resoning that he thinks. and in that case u get an SQLException : Invalid Descriptor Index.
But my problem is SQLException :Function Sequence Error. Now when the the ADD button is clicked for the first time every thing goes in the it shuold but on the next time it gives error on the
//line 2 it prints "After absolute row"+current row no. but not the second print statement and gives the error i told u.
heres the code.
Brief description of the objects and variables.
//**********
ADD is the button on which the code is called
guicreator is my class which has a static connection object for whole of the application.
client_rs is a ResultSet which is currently ie when the control is in the if construct hold the data from the client table of my database.

client is the JComboBox //line 1

[ Edited by Dave to format code ]
[ March 14, 2002: Message edited by: David O'Meara ]
thanks ramachandran for ur help .what u told is already part of my code ie. i commit()on successful execution of query and rollback on Exception but i will check for the case where i might have forget to do that thing.
This SQLException occurs when i call absolute mehtod and then getString method. for the first time the getString method retrieves the data but the next time it gives this Exception, let me clear u one thing that these two methods are called in ActionEvent of button and the ResultSet contains the same data.Pls reply soon with cause of error and its possible remedy as quicky as possible as i am running out of time.
Its my humble request to u all pls suggest the solution to my problem as i am running out of time.
Before i switch over to my problem let megive u brief description of the way i am handling JDBC connection.
I am using jdbc odbc bridge with MS SQL Server 7.0 and jdk1.4 ,a single Connection object and Statement object throughout the project is being used but i also create new Statement objects where it is necessary to get data from two or more than two ResultSet.
This exception (SQLException: Invalid transaction state) comes when i close the main frame of my application where i am trying to close the connection.
What i want to know is what are the reasons due to which this exception can occur and what are the possible solutions to it.
i will be thankfull to u all if u reply soon as i have to submit my project on this 31.
i was also facing the exact problem with my project.i was also confused that why can't we use the getXXX() method on a cell more than once. I don't know whther or not my explanation is right but it worked for me and i am sure it will work for u also.
what i thought was, that , that u can't move to the fields previous to the column u have started fetching the data from a (particular) row.
Suppose u have 5 columns in the table and for a particular row u first executed the getXXX() method on column 3 than after that getXXX() method u can't move on to previous column nor u can again fetch the same column(3) again untill u move the cursor to any other row.
SOLUTION.....
what i did, i took the value of the cell that i need to access again-2 in a variable and then used that variable.
JDBC gurus pls correct me if i am wrong with my reasoning part.
thanks Jamie for ur help i will surely try it .well i am using jdbc dbc bridge for MS SQL server 7.0 .i will check does it work for type 1 according to u or not.
what kind of SQLException is "Invalid Descriptor Index".when does it occur, and how to solve it.
I have a single Statement object for whole of my application i want to know that when i got a ResultSet object after executeQuery() mehtod and then again used the Statement object for another executeQuery() mehtod that again returned a ResultSet object , would the first ResultSet object become unusable or not.