Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class CreaQuestionario {
- private UserSession user;
- private String titolo;
- private String categoria;
- private static final String admin = "fabio@marcoccia.net";
- private UserSession getUserInSession() {
- HttpSession session = ServletActionContext.getRequest().getSession();
- return (UserSession) session.getAttribute(UserSession.KEY);
- }
- public String execute() {
- user = getUserInSession();
- Statement stmt = null;
- Connection conn = null;
- if (user == null) {
- return "erroreNonLoggato";
- } else {
- try {
- String URL = "jdbc:mysql://localhost:3308/tutorial";
- Class.forName("com.mysql.jdbc.Driver");
- conn = DriverManager.getConnection(URL, "root", "Fabio1992");
- stmt = conn.createStatement();
- String sql = "INSERT INTO tutorial.questionario values(0,"
- + "'" + getTitolo() +"', '" + getCategoria() + "', '" + admin + "')";
- System.out.println(sql);
- stmt.executeUpdate(sql);
- } catch (Exception e) {
- e.printStackTrace();
- } finally {
- try {
- if (stmt != null)
- conn.close();
- } catch (SQLException se) {
- }
- if (conn != null) {
- try {
- conn.close();
- } catch (Exception e) {
- }
- }
- }
- return "pagina_admin";
- }
- }
- public String getCategoria() {
- return categoria;
- }
- public void setCategoria(String categoria) {
- this.categoria = categoria;
- }
- public String getTitolo() {
- return titolo;
- }
- public void setTitolo(String titolo) {
- this.titolo = titolo;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement