<%@page import="java.sql.*"%>
<%@page import="java.io.*"%>
<%
String username = request.getParameter("username");
String password = request.getParameter("password");
String connectionURL = "jdbc:mysql://localhost:3306/handle";
Connection connection = null;
PreparedStatement pstatement = null;
Class.forName("com.mysql.jdbc.Driver").newInstance();
int updateQuery = 0;
if(username!=null && password!=null){
try {
connection = DriverManager.getConnection (connectionURL, "test", "test");
String queryString = "INSERT INTO handle(username, password, last_login) VALUES (?, AES_ENCRYPT(?, 'key'), now()) ON DUPLICATE KEY UPDATE last_login=now()";
/* createStatement() is used for create statement
object that is used for sending sql statements to
the specified database. */
pstatement = connection.prepareStatement(queryString);
pstatement.setString(1, username);
pstatement.setString(2, password);
pstatement.setString(3, password);
updateQuery = pstatement.executeUpdate();
if (updateQuery != 0) { %>
<%
}
}
catch (Exception ex) { %>
<%
}
finally {
// close all the connections.
pstatement.close();
connection.close();
}
}
%>
Wednesday, July 1, 2009
Jsp Insert into MySQL database, AES encryption
Jsp code that inserts into a MySQL database, using AES_ENCRYPTION for 128 bit AES encryption of one of the database columns with ON DUPLICATE KEY UPDATE syntax.
Subscribe to:
Post Comments (Atom)


0 comments:
Post a Comment