Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.FileInputStream;
- import java.sql.*;
- import java.util.HashMap;
- import java.util.Map;
- import java.util.Properties;
- public class ProfilesDAOTest {
- public ProfilesDAOTest() throws Exception{
- Connection con = null;
- try {
- Class.forName("com.mysql.jdbc.Driver");
- Properties prop = new Properties();
- prop.load(new FileInputStream("info.properties"));
- String user = prop.getProperty("user");
- String password = prop.getProperty("password");
- String dburl = prop.getProperty("dburl");
- con = DriverManager.getConnection(dburl, user, password);
- } catch (ClassNotFoundException e) {
- e.printStackTrace();
- } catch (SQLException e) {
- e.printStackTrace();
- }
- return ;
- }
- public void updateProfiles (HashMap<String,Integer> theProfiles) throws DAOException{
- PreparedStatement myStmt = null;
- Connection myConn = null;
- String sql = "UPDATE profiles SET user_name=?, nick_name=?, user_mail=?" +
- ", password=?, gender=?, country=?";
- try {
- myConn.setAutoCommit(false);
- myStmt = myConn.prepareStatement(sql);
- for (Map.Entry<String,Integer> e : theProfiles.entrySet()) {
- myStmt.setString(1, String.valueOf(e.getValue().intValue()));
- myStmt.setString(2, String.valueOf(e.getValue().intValue()));
- myStmt.setString(3, String.valueOf(e.getValue().intValue()));
- myStmt.setString(4, String.valueOf(e.getValue().intValue()));
- myStmt.setString(5, String.valueOf(e.getValue().intValue()));
- myStmt.setString(6, String.valueOf(e.getValue().intValue()));
- myStmt.executeUpdate();
- myConn.commit();
- }
- } catch (SQLException e) {
- e.printStackTrace();
- } finally {
- try{
- if (myConn != null) {
- myConn.close();
- }
- if (myStmt != null) {
- myStmt.close();
- }
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement