Created
January 18, 2013 07:12
-
-
Save pikanji/4562891 to your computer and use it in GitHub Desktop.
Sample to access MySQL from Spring MVC.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
try { | |
Class.forName("com.mysql.jdbc.Driver"); // Load driver | |
Connection con = DriverManager.getConnection( | |
"jdbc:mysql://localhost/db_name?useUnicode=true&characterEncoding=UTF-8", | |
"db_user", | |
"db_password" | |
); | |
Statement state = con.createStatement(); | |
String sql = "INSERT INTO `users` (`username`, `password`) VALUES ('hoge', 'fuga')"; | |
state.execute(sql); | |
con.close(); | |
} catch (ClassNotFoundException e) { | |
logger.error(e.getMessage()); | |
} catch (SQLException e) { | |
logger.error(e.getMessage()); | |
} catch (Exception e) { | |
logger.error(e.getMessage()); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment