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



Home Answers Viewqa JDBC reduce complexity

Have Programming Question? Ask it here!
 
 
 


rajesh
reduce complexity
1 Answer(s)      2 years and 5 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:
PHP Function
of functions we can reduce time and effort, all we need to do is create
Advertisements
JAVA certification effort - Framework
JAVA certification effort  Estimated time to certify JAVA on the following platforms? 1. WindRiver Linux PNE LE 2.0 2. RedHat Linux 5.2 What is the complexity of this effort? Thanks. Hans
ArrayList and Vector
ArrayList and Vector  hello, Why ArrayList is faster than Vector?   hii, ArrayList is faster than Vector, because ArrayList is not synchronized. Synchronization will reduce the performance of Vector
java - Java Interview Questions
java  why java don't support operator overloading?  Hi Friend, Overloading provides complexity in code and violates transparency. The effects of operator overloading is easily achieved by declaring a class
j2ee - EJB
to reduce the network traffic. If this is correct or not plz reply
two text box problem
two text box problem  i have two text box in two different pages and same variable use in two text box when enter value in first text box it's reflection show in second text box , how i reduce it in jsf ?   Hi Friend
JSF most popular web application development framework
JSF has simplified handling the complexity and other problems faced during development, specially creating user interfaces for the web applications. You can read the topic ?JSF Introduction? in roseindia.net, which introduces you
java - JSP-Servlet
When to use servlert and when to use JSP?  Hi, i am confuse about when to use servlert and when to use JSP?  When to use servlert and when to use JSP:JSPUse JSP where the complexity of the HTML is the most
Should i use Ajax? - Ajax
we can reduce the unnecessary hits to server/ database. So you can go for AJAX... for creating interactive web applications.Using AJAX we can reduce
servlet - Servlet Interview Questions
. This will reduce the time gap between request and response. And along with that we
java - Java Beginners
that provide specific functions. You can reduce the amount of required storage space
java-jar file creation - Java Beginners
is used to distribute a set of java classes. This file helps you to reduce the file
What is Stored Procedure?
is modified, all clients automatically get the new version. Stored procedures reduce
query optimization - WebSevices
a suitable way for the concern issue,how we can reduce the execution time ofthe
The animation of image using the 'animate' effect of jQuery
attribute (attributes are given inside braces): 1.Can reduce Image opacity(opacity). 2.Can reduce the height of Image(left). 3.Can shift Image position to left
Abstraction : Java Glossary
/beginners/oop-in-java.shtml Abstraction concept is developed to solve the complexity
multiple inheritance - Java Beginners
multiple inheritance  Why java does not support Multiple Inheritance?  First of all the question is wrong the correct one is......... Q... get confused as to which method it should call. This causes complexity
counting identifiers,no.of inputs and outputs - Java Magazine
counting identifiers,no.of inputs and outputs  Hi, my name is jyothi.iam doing my miniproject the title is 'evaluation of complexity measure using cognitive metrics'.actually i want to take the program as input and i want
Segment application
;@implementation SegmentViewController  // segment action and reduce size...); // reduce size of view     second.frame = CGRectMake(0, 80, 320, 400);// reduce size of view     third.frame = CGRectMake(0, 80
PHP Function
of functions we can reduce time and effort, all we need to do is create a function
Code To match password - Development process
Code To match password   Hi, Suppose I have 10 username and passwords in one table.While mapping with while loop it takes little time to match . Is there any way to reduce tat time. Is there any filter of find
Java - Java Interview Questions
pointless complexity of ContentPanes. Though JDK 1.6 is more forgiving, your apps
Submit project to get developed
, such as , the complexity of the project, Language used, Technology used
PHP Installing PHP LAMP - Linux Apache MySQL and PHP Tutorial
complexity using these technologies. Installing LAMP System: There are many
PDO Prepared Statement
, using this we can reduce the execution time. The prepared statement can
Flex 4 Features
to reduce the application size rather than static linking 13. StyleManager
Create UIButton Programmatically
are ok to me .. but i prefer Interface builder to reduce the coding part. But again
Java Methods Problem - Java Beginners
the user how many slices they would like and store it in num. Then i have to reduce
Java Methods Problem - Java Beginners
the user how many slices they would like and store it in num. Then i have to reduce
History of Struts
logic and java code inside the JSP page unnecessary added the complexity
Questions on Spring - Spring
applications based on the Java platform. Because of the size and complexity
Java Parallel Processing Framework (JPPF) version 1.4 is now available
with the complexity of distributed and parallel processing.   It features
Release of Jitterbit 2.0 Enterprise and Community
more on reducing the cost and complexity of enterprise integration
JDBC, Java Database Connectivity
as an abstraction layer and hides the complexity of accessing database. Different database
Biological Databases Links
complexity of cellular processes and organism behaviors from genomic information
What is Persistence Framework?
Maps framework will help to significantly reduce the amount of Java code
Collection of Large Number of Java Interview Questions!
hides the complexity of business components and centralizes the workflow
JSF Tutorial for Beginners
. True! But, the technolgy should hide all that complexity and make the coder feel
An introduction to spring framework
objects. But a number of enterprise projects do not have this level of complexity
 

 

 

DMCA.com