Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to run sql queries using JSTL

    • 0
    • 1
    • 1
    • 2
    • 0
    • 0
    • 0
    • 0
    • 214
    Comment on it

    Run sql queries using SQL tag in JSP

    We can run SQL queries directly in JSP page using "sql" tag.
    Suppose we have a 'postgres' database, with below credentials:
    db:'test'
    user: root
    password: 123
    table name: user which have a column 'userName'.
    Below is the JSP code to make db connection and get data from table:

    <body>
         <sql:setDataSource var="connection" driver="org.postgresql.Driver" url="jdbc:postgresql://localhost/test" user="root" password="123" />
         <sql:query dataSource="${connection}" var="result" >
               select userName from user;
         </sql:query>
         <c:forEach var="row" items="${result.rows}">
               <c:out value="${row.userName}"/>
         </c:forEach>
    </body>
    

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: