D
D
Dom Topor2014-03-20 03:12:02
Java
Dom Topor, 2014-03-20 03:12:02

Why does the program not display the result of the query execution on the screen when addressing a parameter to the query?

The program does not display the result of the query execution on the screen when addressing a parameter to the query.
Although if you replace the question mark in the request with a specific value, then everything works.
What is the problem and how to fix it?

String tourName = "Egypt";      
        PreparedStatement pstmt = connection.prepareStatement(
        "SELECT TOURS.TOUR_NAME, TOURS.TOUR_PLACE ,\n" +
        "TOURS.TOUR_DURATION , TOURS.TOUR_DESCRIPTION ,TOURS.TOUR_PRICE ,\n" +
        "VENDORS.VENDOR_COMPANY_NAME , VENDORS.VENDOR_ADDRESS ,\n" +
        "VENDORS.VENDOR_PHONE , VENDORS.VENDOR_MAIL ,VENDORS.VENDOR_FAX \n" +
        "FROM VIKTOR.TOURS INNER JOIN VENDORS \n" +
        "ON VIKTOR.TOURS.VENDOR_COMPANY_NAME = VENDORS.VENDOR_COMPANY_NAME\n" +
        "WHERE VIKTOR.TOURS.TOUR_NAME = ?");
        pstmt.setString(1,tourName);
        pstmt.execute();
        ResultSet resultSet = pstmt.executeQuery();
   
        ResultSetMetaData metaData = resultSet.getMetaData();
        int tableCollumnCount = metaData.getColumnCount();
        String m;
        int k=1;
        int v = 1;
         
        while (resultSet.next()) {
            while (k <= tableCollumnCount) {
                m = resultSet.getString(kiss);
                System.out.println(e);
                k++;
             }      
           }
        connection.close(); 
<code lang="java">

Answer the question

In order to leave comments, you need to log in

3 answer(s)
D
Dom Topor, 2014-04-11
@deleted-Ari100teLL

Thanks to everyone for the answers, but it turned out that the problem was solved by replacing the field type in the database: the type CHAR (100) was VARCHAR (100)

N
NuMooLe, 2014-03-21
@NuMooLe

You need to remove the newline from the query ("\n").

S
st_alx, 2014-04-10
@st_alx

or remove
pstmt.execute();
or
replace
ResultSet resultSet = pstmt.executeQuery();
on
ResultSet resultSet = pstmt.getResultSet()

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question