1

i have built quiz web project. i want to insert below mentioned test question into database. i am writing this question in html textarea, then getdata from html with inner.html :

enter image description here

but when i select this question from database it looks like that, it is hard readable, carelessly written:

enter image description here

help me make above mentioned tests readable.

my sql insert code :

 public void addtest(TestModel test) throws Exception {
    Connection c = null;
    PreparedStatement ps = null;
 String sql = "INSERT INTO TEST_TABLE (QUESTION,A,B,C,D,E,QUESTION_TYPE,SCORE,SUBJECT, CORRECT, Variant) " +
                 " VALUES (?,?,?,?,?,?,?,?,?,?,?) ";

    try {

        c= DbHelper.getConnection();
        if(c != null) {
            ps = c.prepareStatement(sql);
            ps.setString(1,test.getQuestion());
            ps.setString(2,test.getOptionA());
            ps.setString(3,test.getOptionB());
            ps.setString(4,test.getOptionC());
            ps.setString(5,test.getOptionD());
            ps.setString(6,test.getOptionE());
            ps.setString(7,test.getQuestionType());
            ps.setLong(8,test.getScore());
            ps.setLong(9,test.getSubjectId());
            ps.setString(10,test.getCorrectOption());
            ps.setInt(11,test.getVariant());


            ps.execute();

        }  else {
            System.out.println("Connection is null");
        }
    }  catch (Exception ex)  {
        ex.printStackTrace();

    }  finally {

        JdbcUtility.close(c,ps,null);
    }

}

my sql select code :

     public TestModel getquestionlist(long firstpage,int variant) throws Exception {
    TestModel testdata = new TestModel();

    Connection c = null;
    PreparedStatement ps = null;
    ResultSet rs = null;

    String sql =" SELECT  TE.ID,TE.QUESTION,TE.A,TE.B,TE.C,TE.D,TE.E,TE.F,TE.G,TE.QUESTION_TYPE,TE.SCORE,S.NAME as Subject,TE.CREATE_DAY,TE.CORRECT, d.value, TE.Variant FROM TEST_TABLE TE " +
            "INNER JOIN SUBJECT S ON  S.ID = TE.SUBJECT " +
            "inner join dictionary d on d.ID = TE.Variant " +
            "WHERE TE.ACTIVE =1 AND S.ACTIVE =1 AND TE.Variant = ? " +
            "LIMIT ?,1; ";

    try {

        c = DbHelper.getConnection();

        if (c != null) {

            ps = c.prepareStatement(sql);
            ps.setInt(1,variant);
            ps.setLong(2,  firstpage);

            rs = ps.executeQuery();

            while (rs.next()) {

                testdata.setId(rs.getLong("ID"));
                testdata.setQuestion(rs.getString("QUESTION"));
                testdata.setOptionA(rs.getString("A"));
                testdata.setOptionB(rs.getString("B"));
                testdata.setOptionC(rs.getString("C"));
                testdata.setOptionD(rs.getString("D"));
                testdata.setOptionE(rs.getString("E"));
                testdata.setOptionF(rs.getString("F"));
                testdata.setOptionG(rs.getString("G"));
                testdata.setQuestionType(rs.getString("QUESTION_TYPE"));
                testdata.setScore(rs.getLong("SCORE"));
                testdata.setTestSubject(rs.getString("Subject"));
                testdata.setCreateDate(rs.getDate("CREATE_DAY"));
                testdata.setCorrectOption(rs.getString("CORRECT"));
                testdata.setVariant(rs.getInt("Variant"));

            }

        }
    } catch (Exception ex) {
        ex.printStackTrace();
    } finally {
        JdbcUtility.close(c, ps, rs);
    }

    return testdata;
}
Islam Ismayilov
  • 111
  • 1
  • 11
  • mmm, your question is not clear can you explain more? – Youcef LAIDANI May 04 '17 at 18:32
  • i have add 2 pictures: first picture describe question- i have capured from pdf file. the second picture i have captured from my web application when i select test question from datase. i want to describe test question in my web application as it was in pdf file. – Islam Ismayilov May 04 '17 at 18:37
  • You are probably looking for html `
    `, see http://stackoverflow.com/questions/4611591/code-vs-pre-vs-samp-for-inline-and-block-code-snippets for example
    –  May 04 '17 at 18:38
  • This looks like it has to do with the view you are rendering as a web page, not an SQL issue. You appear to be just dumping the `toString()` of a `TestModel` on the page. Post your HTML (or JSP or whatever) that deals with the returned `TestModel` – Stephen P May 04 '17 at 19:14
  • and
    worked. thanks a lot.
    – Islam Ismayilov May 04 '17 at 19:45

1 Answers1

1

You can use <br/> to break line :

"1: public class WaterBottle { <br/>"

So in the moment of getting the result you can concatenate your result with <br/> for example :

testdata.setQuestion(rs.getString("QUESTION") + "<br/>");
Youcef LAIDANI
  • 55,661
  • 15
  • 90
  • 140