-1
/*
 * 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...

Edited by Ezzaral: Added [code] [/code] tags. Please use them to format any code that you post.

2
Contributors
6
Replies
8
Views
7 Years
Discussion Span
Last Post by peter_budo
0

Problem description is missing, how we are supposed to know what sort of errors you getting. Plus there is no chance to second-guess what you trying to achieve...

0

Sorry for that....
I have written the cod ein net beans....here am trying to connect to MYsql database and retrieve data from there...........
The errors that iam receiving are

com.mysql.jdbc.JDBC4Connection@c58418

Failed to initalize plugin: org.jboss.logging.Log4jLoggerPlugin@12a74c7, cause: org/apache/log4j/LogManager

0

am also getting this error

A message body writer for Java type, class Programs.ProgramDetailsList, and MIME media type, application/xml, was not found

am unable to figure out whether am going wrong in my code or is there
some jar files missing

0

Sorry for that....
I have written the cod ein net beans....here am trying to connect to MYsql database and retrieve data from there...........
The errors that iam receiving are

com.mysql.jdbc.JDBC4Connection@c58418

Failed to initalize plugin: org.jboss.logging.Log4jLoggerPlugin@12a74c7, cause: org/apache/log4j/LogManager

You did not imported Logger into your code as other packages

import org.jboss.logging.Logger;

Full JBoss documentation on topic here
EDIT:
You actually tried but did it wrong import java.util.logging.Logger;

am also getting this error

A message body writer for Java type, class Programs.ProgramDetailsList, and MIME media type, application/xml, was not found

am unable to figure out whether am going wrong in my code or is there
some jar files missing

Full error description as given by compiler plus relevant coding need to see what is going on. You should know this...

Edited by peter_budo: EDIT

0

You did not imported Logger into your code as other packages

import org.jboss.logging.Logger;

Full JBoss documentation on topic here
EDIT:
You actually tried but did it wrong import java.util.logging.Logger; Full error description as given by compiler plus relevant coding need to see what is going on. You should know this...

Thanks a lot for spotting my error:)

0

So is this solved now or there is something else you want to ask?
If it is solved, please mark it as solved by clicking on "Mark as Solved" bellow last post.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.