/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package Programs;
import java.util.ArrayList;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.UriInfo;
import javax.ws.rs.Consumes;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.GET;
import javax.ws.rs.Produces;
import java.util.List;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
* REST Web Service
*
* @author Dhanya_Kurup
*/
@Path("ProgramList")
public class ProgramListResource {
@Context
private UriInfo context;
private Logger logger = Logger.getLogger(this.getClass().getName());
/** Creates a new instance of ProgramListResource */
public ProgramListResource() {
}
/**
* Retrieves representation of an instance of Programs.ProgramListResource
* @return an instance of java.lang.String
*/
@GET
@Produces("application/xml")
public ProgramDetailsList getXml() {
//TODO return proper representation object
//throw new UnsupportedOperationException();
//String Strqry;
Connection connection = null ;
String connectionURL = "jdbc:mysql://localhost:3306/test";
ProgramDetailsList Details = new ProgramDetailsList();
try
{
ResultSet programResults = null;
Class.forName("com.mysql.jdbc.Driver").newInstance();
connection = (Connection) DriverManager.getConnection(connectionURL, "root", "bharani");
logger.log(Level.INFO, "conncetion: " + connection);
Statement stmt = connection.createStatement();
stmt.setQueryTimeout(120);
programResults = stmt.executeQuery("select * from programlist");
//programResults=Strqry;
System.out.println("hii");
List<String> programName=new ArrayList<String>();
//programName=null;
List<String> duration=new ArrayList<String>();
List<String> days=new ArrayList<String>();
List<String> programType=new ArrayList<String>();
List<String> description=new ArrayList<String>();
while(programResults.next())
{
programName.add(programResults.getString("ProgramName"));
duration.add(programResults.getString("Duration"));
days.add(programResults.getString("Days"));
programType.add(programResults.getString("ProgramType"));
description.add(programResults.getString("Description"));
}
int length=programName.size();
List<ProgramDetails> program_list=new ArrayList<ProgramDetails>();
for(int k=0;k<length;k++)
{
ProgramDetails program = new ProgramDetails();
program.ProgramName=programName.get(k);
program.Duration=duration.get(k);
program.Days=days.get(k);
program.ProgramType=programType.get(k);
program.Description=description.get(k);
program_list.add(program);
}
Details.programDetailsList=program_list;
stmt.close();
programResults.close();
}
catch (Exception ex)
{
Logger.getLogger(ProgramListResource.class.getName()).log(Level.SEVERE, null, ex);
}
finally
{
try
{
connection.close();
}
catch (SQLException ex)
{
Logger.getLogger(ProgramListResource.class.getName()).log(Level.SEVERE, null, ex);
}
}
return Details;
}
/**
* PUT method for updating or creating an instance of ProgramListResource
* @param content representation for the resource
* @return an HTTP response with content of the updated or created resource.
*/
@PUT
@Consumes("application/xml")
public void putXml(String content) {
}
}
this is the code that i have written....
bt its not executing
Please help...