Servlet
Welcome to my Blog! This is my first article. The following are my study notes for learning Servlet.
Reasonable use of SQL statements
String sql = "insert into T_BOOK(BID,BNAME,BAUTHER,BTYPE,BPRICE,BAMOUNT,BPUBDATE)";
sql=sql+" values('"+BID+"','"+BNAME+"','"+BAUTHER+"','"+BTYPE+"','"+BPRICE+"',"+BAMOUNT+",'"+BPUBDATE+"')";
String sql = "update T_BOOK set BAMOUNT = "+BAMOUNT+" where BID = '"+BID+"'";
String sql = "select * from T_BOOK where BNAME like '%"+input+"%'";
String sql = "select * from T_BOOK where BPRICE between "+Low+" and "+High;
Proficiency in the SQL language is a prerequisite for implementing various operations through the servlet link to the database.
Mastering the most basic insert, update and conditional search statements can achieve most database operations.
Connect to the database via JDBC
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver").newInstance();
String url="jdbc:sqlserver://localhost:1433;databaseName=?";
String user="user";
String password="password";
conn=DriverManager.getConnection(url, user, password);
The project adopting MVC mode is to use JDBC technology to connect to the database.
Please add sqljdbc.jar in the lib folder of WEB-INF to ensure that JDBC can be successfully called.
Use of Servlet annotations
@WebServlet("/Classname")
Using Servlet annotations can eliminate extra comments in web.xml, making the program more concise and portable.
Thank you for reading, I hope these tips can help you learn Servlet better.
本博客所有文章除特别声明外,均采用 CC BY-SA 4.0 协议 ,转载请注明出处!