java连接mysql数据库例⼦代码记得设置时区,数据库编码在URL中,否则连接不上
1 @RequestMapping(value="/record")
2public String record() {
java的jdbc连接数据库3try {
4 Class.forName("sql.cj.jdbc.Driver");
5 String url = "jdbc:mysql://127.0.0.1/eam?serverTimezone=GMT%2B8&useUnicode=true&characterEncoding=UTF-8";
6 String username = "root";
7 String pass = "root";
8try {
9 Connection con = Connection(url, username, pass);
10 Statement st = ateStatement();
11 ResultSet rs = st.executeQuery("select * from operation");
()) {
13 System.out.Int(1));
14 System.out.String(2));
15 System.out.String(3));
16 System.out.String(4));
17 }
18 } catch (SQLException e) {
19// TODO Auto-generated catch block
20 System.out.println("数据库连接失败"+e.getMessage());
21 }
22
23 } catch (ClassNotFoundException e) {
24// TODO Auto-generated catch block
25 System.out.println("驱动程序加载失败");
26 }
27 System.out.println("进⼊record");
28return "record";
29 }
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论