hi i want to retrieve values from SQL database for xml tags using java coding
i hav written a code to connect database… i am able to query the database… created a .xml file using documentbuliderfactory and transformerfactory.Now output is like this
public class New
void condb() { /*written code to connect databse*/
try {
/*code for get xml tags*/
stmt = connection.createStatement();
String querystring = ("select CId from company");
rs = stmt.executeQuery(querystring);
System.out.println("\n" + "CId");
while (rs.next()) {
System.out.println(rs.getInt(1) + " ");
}
Element child1 = doc.createElement("Company");
child1.setAttributeNS(xlink, "xlink:type", ""); child1.setAttributeNS(xlink, "xlink:show", " ");
child.appendChild(child1);
/*code for xml*/
bw.flush();
bw.close();
} catch (Exception e) {
System.out.println("Exception in connecting to DB" + e.getMessage());
System.err.println(e.getMessage());
}
}
public static void main(String args[]) throws Exception {
New e = new New();
e.condb();
}
}
i want to get values for xlink:type=” ” and xlink:show=””from database … i tried declaring variable name and assigning queries to it,called that variable name in the ” ” field.. but it doesn’t work… please can anybody help me to solve this problem.
As I understand you need to store in xml the company list from your database.
Try this:
Though I don’t quite understand your sql query
Is company a table or some other select query?