Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa JDBC reduce complexity
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


rajesh
reduce complexity
1 Answer(s)      2 years and 6 months ago
Posted in : JDBC


I want to make the logic simple.all suggestions welcomed servlet

//Update3
            int testid = Integer.parseInt(request.getParameter("testid"));
            int question1 = Integer.parseInt(request
                    .getParameter("questionid1"));
            int question2 = Integer.parseInt(request
                    .getParameter("questionid2"));
            int question3 = Integer.parseInt(request
                    .getParameter("questionid3"));
            int question4 = Integer.parseInt(request
                    .getParameter("questionid4"));
            int question5 = Integer.parseInt(request
                    .getParameter("questionid5"));
            int question6 = Integer.parseInt(request
                    .getParameter("questionid6"));
            int question7 = Integer.parseInt(request
                    .getParameter("questionid7"));
            int question8 = Integer.parseInt(request
                    .getParameter("questionid8"));
            int question9 = Integer.parseInt(request
                    .getParameter("questionid9"));
            int question10 = Integer.parseInt(request
                    .getParameter("questionid10"));

        TestVO question = new TestVO();

        question.setTestId(testid);
        question.setQuestionId1(question1);
        question.setQuestionId2(question2);
        question.setQuestionId3(question3);
        question.setQuestionId4(question4);
        question.setQuestionId5(question5);
        question.setQuestionId6(question6);
        question.setQuestionId7(question7);
        question.setQuestionId8(question8);
        question.setQuestionId9(question9);
        question.setQuestionId10(question10);

        UpdateQntoTestService upques = new UpdateQntoTestService();
        int count = upques.updateQuestion(question);
        // Success Page
        if (count >= 1) {
            request.setAttribute("mycount", count);
            RequestDispatcher rd1 = getServletContext()
                    .getRequestDispatcher("/JSP/UpdateQntoTestSuccess.jsp");
            rd1.forward(request, response);
            // ErrorPage
        } else {
            RequestDispatcher rd1 = getServletContext()
                    .getRequestDispatcher("/JSP/UpdateQntoTestFailure.jsp");
            rd1.forward(request, response);
        }
    }
    // Servlet for UpdateTest
    else if (pagename.equalsIgnoreCase("update1")) {

        int testId = Integer.parseInt(request.getParameter("testId"));
        ViewQnfromTest1Service vqs = new ViewQnfromTest1Service();

        HashMap<Integer, TestVO> ar = null;
        try {
            ar = vqs.viewQuestions(testId);
        } catch (SQLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }


        log.info(ar);
        request.setAttribute("arr", ar);
        RequestDispatcher rd1 = getServletContext().getRequestDispatcher(
                "/JSP/UpdateQuestiontoTestDB.jsp");
        rd1.forward(request, response);

    }
    // Servlet for UpdateQuestion
    else if (pagename.equals("update2")) {
        log.info(pagename);

        RequestDispatcher rd1 = getServletContext().getRequestDispatcher(
                "/JSP/UpdateQuestiontoTestFinal.jsp");
        String test1 = request.getParameter("testId1");
        String qn1 = request.getParameter("questionId1");
        String qn2 = request.getParameter("questionId2");
        String qn3 = request.getParameter("questionId3");
        String qn4 = request.getParameter("questionId4");
        String qn5 = request.getParameter("questionId5");
        String qn6 = request.getParameter("questionId6");
        String qn7 = request.getParameter("questionId7");
        String qn8 = request.getParameter("questionId8");
        String qn9 = request.getParameter("questionId9");
        String qn10 = request.getParameter("questionId10");
        request.setAttribute("testId1", test1);
        request.setAttribute("qid1", qn1);
        request.setAttribute("qid2", qn2);
        request.setAttribute("qid3", qn3);
        request.setAttribute("qid4", qn4);
        request.setAttribute("qid5", qn5);
        request.setAttribute("qid6", qn6);
        request.setAttribute("qid7", qn7);
        request.setAttribute("qid8", qn8);
        request.setAttribute("qid9", qn9);
        request.setAttribute("qid10", qn10);

        try {
            rd1.forward(request, response);
        } catch (ServletException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

service

public class ViewQnfromTestService {

public List<TestVO> calculate(int testId) {
    List ls = null;

    ViewQnfromTest1DAO daoobject = new ViewQnfromTest1DAO();
    try {
        ls = daoobject.count(testId);
    } catch (SQLException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        ls = null;
    }

    return ls;

service3

public class UpdateQntoTestService {

TestVO question;
int choice = 1;
int count = 0;

public int updateQuestion(TestVO question) {
    this.question = question;
    UpdateQntoTestDAO qud = new UpdateQntoTestDAO();
    try {
        count = qud.QuestionUpdate(question);
    } catch (SQLException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return count;

}

dao

public class ViewQnfromTest1DAO {

public List<TestVO> count(int testId) throws SQLException {
    TestVO ts = new TestVO();
    PreparedStatement pst = null;
    ConnectOracle conn = new ConnectOracle();
    Connection con = null;
    System.out.println("Ajs qqq");
    List ls = new ArrayList();
    try {
        con = conn.getConnectionOra();
        pst = con.prepareStatement(QueryConstants.VIEWQNFROMTEST);
        pst.setInt(1, testId);
        ResultSet rs1 = null;
        rs1 = pst.executeQuery();

        if(rs1 == null)
            return null;
        while (rs1.next()) {
            System.out.println(rs1.getInt(1));
            ts.setTestId(testId);
            ts.setQuestionId1(rs1.getInt(1));
            ts.setQuestionId2(rs1.getInt(2));
            ts.setQuestionId3(rs1.getInt(3));
            ts.setQuestionId4(rs1.getInt(4));
            ts.setQuestionId5(rs1.getInt(5));
            ts.setQuestionId6(rs1.getInt(6));
            ts.setQuestionId7(rs1.getInt(7));
            ts.setQuestionId8(rs1.getInt(8));
            ts.setQuestionId9(rs1.getInt(9));
            ts.setQuestionId10(rs1.getInt(10));
            ls.add(ts);
            System.out.println(ts);
        }
        if(ls == null)
            return null;

    } catch (Exception e) {
        e.printStackTrace();

        ls=null;
    }

    finally
    {
        con.close();
    }
    return ls;
}

dao2

public class UpdateQntoTestDAO {

int count = 0;
Connection conn = null;

@SuppressWarnings("finally")
public int QuestionUpdate(TestVO question) throws SQLException {
    ConnectOracle connect = new ConnectOracle();

    try {
        // Creation of Connection instance.

        conn = connect.getConnectionOra();

        // PreparedStatement usage for inserting Question Details.

        PreparedStatement pst = conn
                .prepareStatement(QueryConstants.UPDATEQNTOTEST);

        pst.setInt(1, question.getQuestionId1());
        pst.setInt(2, question.getQuestionId2());
        pst.setInt(3, question.getQuestionId3());
        pst.setInt(4, question.getQuestionId4());
        pst.setInt(5, question.getQuestionId5());
        pst.setInt(6, question.getQuestionId6());
        pst.setInt(7, question.getQuestionId7());
        pst.setInt(8, question.getQuestionId8());
        pst.setInt(9, question.getQuestionId9());
        pst.setInt(10, question.getQuestionId10());
        pst.setInt(11, question.getTestId());

        // Execute statement
        count = pst.executeUpdate();

    } catch (Exception ex) {
        ex.printStackTrace();
    }
    finally {
        conn.close();
    }
    return count;

}

}


Advertisement
View Answers

April 2, 2012 at 3:37 PM




Related Tutorials/Questions & Answers:
reduce complexity
reduce complexity  I want to make the logic simple.all suggestions welcomed servlet //Update3 int testid = Integer.parseInt(request.getParameter("testid")); int question1 = Integer.parseInt(request
how to reduce width of jbutton ?
how to reduce width of jbutton ?  how to reduce width of jbutton ? thanks in advancwe
Advertisements
how can u reduce the size of textfield?
how can u reduce the size of textfield?  how can u reduce the size of textfield? thanks in advance   import javax.swing.*; public class ReduceTextField extends JFrame { public static void main(String
Reduce Java Code commenting effort using JAutodoc (eclipse plugin)
Reduce Java Code commenting effort using JAutodoc (eclipse plugin)       INTRODUCTION Summary JAutodoc is a very useful eclipse plugin which
Ant4Eclipse
Ant4Eclipse       The aim of the ant4eclipse project is to avoid (or at least: to reduce) the redundancy of Eclipse and Ant configurations. More precisly: it consists
DEMOS
DEMOS       The DEMOS tool originated in the context of two research projects (FACTORS and DASCOM) dealing with software complexity. The DEMOS tool is based on a new
RefactorIt
RefactorIt         RefactorIT is a tool for Java developers. A developer can take source code of any size and complexity and rework it into well-designed code
Weight Loss
to control your weight. Yogic exercises are best way to reduce and control
Design patterns interview questions3
. This pattern hides the complexity of business components and centralizes the workflow... and locating services and encapsulating their complexity. It provides a single..., abstracts the data sources and hides the complexity of Data persistence layer
Getting a Property value in jsp
Getting a Property value in jsp       This section illustrates you how to use <jsp:getProperty> tag. To reduce the the scriplet code with jsp, there is an easier way
PaperClips
PaperClips       A simple, light weight, extensible Java printing plug-in for SWT. PaperClips hides the complexity of laying out and rendering documents on the printer
eUML2 Studio edition
UML in action at the development level: ensure the software quality and reduce
PHP Function
of functions we can reduce time and effort, all we need to do is create
GPS Tracking for Cars
to reduce the security issues which is a prime concern of the car owners due... to reduce the risk of accidents to a great extent. Another emerging and advance
Software Testing Services, Application Testing Solutions, Testing Services from Rose India
in software testing is branched out from the complexity of software. Testing is more
Eclipse Plunging/Web Services
. Whether visually programming with Java? frameworks that reduce development
Extreme Project Management
in the software industry where the complexity of projects is very high and the nature
TruStudioPHP
. DLTK is comprised of a set of extensible frameworks designed to reduce the complexity of building full featured development environments for dynamic languages
TruStudio Foundation
of extensible frameworks designed to reduce the complexity of building full
Controler as JSP - JSP-Interview Questions
dat it will be more easier to know n also it will reduce the complexity of code
The application will assist surgeon offices to make prioritize surgery bookings.
and availability, reduce guesswork and lower the complexity of booking. I am
The application will assist surgeon offices to make prioritize surgery bookings.
and availability, reduce guesswork and lower the complexity of booking. I am
Shortcomings And Restrictions of RIAs
developers can reduce the delay time by compressing the scripts, and by staging... complex and difficult to handle. The additional complexity of RIA makes them
Shortcomings And Restrictions of RIAs
reduce the delay time by compressing the scripts, and by staging their delivery over... and difficult to handle. The additional complexity of RIA makes them harder to design
Flex - Development process
Flex   hi All, In flex how to reduce the spaces between the column in column chart. My ColumnWidthRation is 0.4 without changing this value how to reduce the spaces between the bar? Thanks, aravindakumarThangaraju
java
java  which has the high time complexity??? a program having 100 lines of code or a program which goes to its loop 100 times
Advertisements
 

 

 

DMCA.com