diff options
author | Vitaly Takmazov | 2016-02-02 14:36:04 +0300 |
---|---|---|
committer | Vitaly Takmazov | 2016-02-02 14:36:04 +0300 |
commit | bd3892546b51f0d31e959d45c138b009d35b2692 (patch) | |
tree | 3c3945f114472344cc3a8866391fa08f02975143 /src/main/java/com/juick/http/www/Settings.java | |
parent | f2a2660e753fa11478fd3edadfdff9c000b22cc9 (diff) |
spring-jdbc
Diffstat (limited to 'src/main/java/com/juick/http/www/Settings.java')
-rw-r--r-- | src/main/java/com/juick/http/www/Settings.java | 31 |
1 files changed, 10 insertions, 21 deletions
diff --git a/src/main/java/com/juick/http/www/Settings.java b/src/main/java/com/juick/http/www/Settings.java index de37bdd0..3713157f 100644 --- a/src/main/java/com/juick/http/www/Settings.java +++ b/src/main/java/com/juick/http/www/Settings.java @@ -17,15 +17,14 @@ */ package com.juick.http.www; -import java.io.IOException; -import java.io.PrintWriter; -import java.sql.Connection; -import java.sql.PreparedStatement; -import java.sql.SQLException; +import org.springframework.jdbc.core.JdbcTemplate; + import javax.servlet.ServletException; import javax.servlet.http.Cookie; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; +import java.io.IOException; +import java.io.PrintWriter; /** * @@ -33,12 +32,12 @@ import javax.servlet.http.HttpServletResponse; */ public class Settings { - protected void doGet(Connection sql, HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + protected void doGet(JdbcTemplate sql, HttpServletRequest request, + HttpServletResponse response) throws ServletException, IOException { com.juick.User visitor = Utils.getVisitorUser(sql, request, response); response.setContentType("text/html; charset=UTF-8"); - PrintWriter out = response.getWriter(); - try { + try (PrintWriter out = response.getWriter()) { PageTemplates.pageHead(out, "Логин", ""); PageTemplates.pageNavigation(out, visitor, null); @@ -56,12 +55,11 @@ public class Settings { PageTemplates.pageFooter(request, out, visitor, false); PageTemplates.pageEnd(out); - } finally { - out.close(); } } - protected void doPost(Connection sql, HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + protected void doPost(JdbcTemplate sql, HttpServletRequest request, + HttpServletResponse response) throws ServletException, IOException { String username = request.getParameter("username"); String password = request.getParameter("password"); if (username == null || password == null || username.length() > 32 || password.isEmpty()) { @@ -79,16 +77,7 @@ public class Settings { if (uid > 0) { - PreparedStatement stmt = null; - try { - stmt = sql.prepareStatement("DELETE FROM logins WHERE user_id=?"); - stmt.setInt(1, uid); - stmt.executeUpdate(); - } catch (SQLException e) { - System.err.println(e); - } finally { - Utils.finishSQL(null, stmt); - } + sql.update("DELETE FROM logins WHERE user_id=?", uid); } String referer = request.getHeader("Referer"); |