Examples of mixed use of JSP and SQL statements

Time:2020-10-22

If you don’t say much, just give me an example
insert

Copy codeThe code is as follows:
String sql=”insert into allorder values(‘” + orderid + “‘,'” + bookid +”‘,'” + amount + “‘,'” + username + “‘)”;
int result=stmt.executeUpdate(sql);
if(result==1)
response.sendRedirect(“index.jsp”);
else
response.sendRedirect(“detail.jsp”);

delete

Copy codeThe code is as follows:
String condition=”delete from allorder where id='”+ orderid+ “‘”;
int result=stmt.executeUpdate(condition);

if(result==1)
response.sendRedirect(“index.jsp”);
else
out.println(“shopCar.jsp”);

update

Copy codeThe code is as follows:
It’s similar to delete and insert

select
[code]
<%
while (rs.next()){
String amount=rs.getString(“amount”);
String orderid=rs.getString(“id”);
String bookname=rs.getString(“name”);
String price=rs.getString(“price”);
String picture=rs.getString(“pic”);

//out.println(“\tshuliang”+amount);
%>
< tr > < td > < td > <% = OrderID% > < td > < td > < td > <% = picture% > < td > < td > <% = bookname% > < td > < td > < price% > < td > < td > <% = amount% > < / td > < td > < Table > < tr > < td > < input type = button “value = delete” onclick “=“ window.location.href= ‘ delete.jsp?orderid= <%=orderid %>'”></td></tr></table></td></tr>
<%
}
//Close connection
stmt.close (); / / close command object connection
con.close (); / / close database connection
} catch (SQLException e) {
e.printStackTrace();
out.println (“database connection error”);
System.exit(0);
}
//Database connection completed
%>
</table>

Recommended Today

Explain module, import and export in JavaScript

Author: Tania rascia Crazy technology house Original text:https://www.taniarascia.com/j… In the era of the Internet, websites are mainly developed with HTML and CSS. If you load JavaScript into a page, it usually provides effects and interactions in the form of small fragments. Generally, all JavaScript code is written in a file and loaded into a filescriptTag. […]