1,105,344 Community Members

writing the content in one file...?

Member Avatar
jeraldmuthu
Newbie Poster
15 posts since Jan 2011
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 
import java.sql.*;

import javax.xml.parsers.*;
import javax.xml.transform.*;
import javax.xml.transform.dom.*;
import javax.xml.transform.stream.*;
import java.io.*;

import javax.servlet.ServletException;
import javax.servlet.ServletConfig;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpServletRequest;

public class MySer extends HttpServlet
{
public void init(ServletConfig config) throws ServletException
{
super.init(config);
}
public void doGet(HttpServletRequest req,HttpServletResponse res) throws ServletException,java.io.IOException
{
String xml;
Connection conn = null;
Statement stmt = null;
ResultSet rs = null;
java.io.PrintWriter out=null;

try
{
res.setContentType("text/html");
out=res.getWriter();


xml = "<chart>";
xml+= "<axis_value shadow='low' size='10' color='000000' alpha='50' steps='6' prefix='' suffix='' decimals='0' separator='' show_min='true' />";
xml+= "<axis_category shadow='low'/>";
xml+= "<chart_border color='000000' top_thickness='0' bottom_thickness='3' left_thickness='0' right_thickness='0'/>";
xml+="<chart_data>";
xml+="<row>";
xml+="<null/>";

}
catch (java.io.IOException e)
{
	System.out.println(e.getMessage());
}

try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");	
}
catch (ClassNotFoundException e)
{
 System.err.println(e);
}


try
{

conn = DriverManager.getConnection("jdbc:odbc:jerry","system","systemm");

stmt  = conn.createStatement();

rs= stmt.executeQuery("select * from SOFTWAREDEVELOPER");
                        
                        
while(rs.next()){
//String xml2 = xml;
String xml;
xml+="<string>";
xml+=rs.getInt(3);
xml+="</string>";
out.println(xml);
//out.println("<tr> <td>"+rs.getInt(1)+"</td><td>"+rs.getString(2)+"</td><td>"+rs.getInt(3)+"</td> </tr>");

 }
 }
 catch(SQLException e)
{
 System.err.println(e);
}

xml+="</row>";
xml+="</chart_data>";
xml+="<chart_grid_h alpha='20' color='000000' thickness='1' type='solid' />";
xml+="<chart_grid_v alpha='20' color='000000' thickness='1' type='dashed' />";
xml+="<chart_rect shadow='bg' x='125' y='65' width='280' height='200' positive_color='eeeeff' negative_color='ff4400' positive_alpha='90' negative_alpha='75' />";
xml+="<chart_transition type='drop' delay='0' duration='3' order='series' />";
xml+="<chart_type>stacked column</chart_type>";
Writer output1 = null;
File file1 = new File("C:\\Users\\sbabu\\Desktop\\stest.xml");
output1 = new BufferedWriter(new FileWriter(file1));
output1.write(xml);
out.println(xml);
}
}

when i'm running this servlet i'm getting the error

String xml is already defined in doGet(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse)

How i write this in one file..
Please Help me...

Member Avatar
stultuske
Posting Expert
5,308 posts since Jan 2007
Reputation Points: 938 [?]
Q&As Helped to Solve: 776 [?]
Skill Endorsements: 35 [?]
Featured
 
0
 

this has nothing to do with separate files or not.
when you use variables, your variables need to have unique names, so, either you rename your second String xml; (and also in all the places you refer to this one, or you remove this line, since String xml already exists.

Member Avatar
hfx642
Posting Pro
515 posts since Nov 2009
Reputation Points: 164 [?]
Q&As Helped to Solve: 105 [?]
Skill Endorsements: 1 [?]
 
0
 

You are defining your variable "xml" twice in the same method.
Line #24 and #72.

You
This article has been dead for over three months: Start a new discussion instead
Post:
Start New Discussion
View similar articles that have also been tagged: