Java-MySQL连接

时间:2017-09-03 18:25:20   收藏:0   阅读:306

一、复制mysql连接工具

技术分享

二、粘贴到MyEclipse

技术分享

三、建立连接

技术分享

四、代码操作

技术分享

技术分享

 

 

 1 public class DDLDemo02 {
 2     public static void main(String[] args) throws Exception {
 3         String sql = "CREATE TABLE `t_student`(`id` " +
 4                 "BIGINT PRIMARY KEY AUTO_INCREMENT," +
 5                 " `name` VARCHAR(255), `age` INT)";
 6         
 7 //        1.加载注册驱动
 8         Class.forName("com.mysql.jdbc.Driver");
 9 //        2.获取连接对象
10         Connection con = DriverManager.getConnection("" +
11                 "jdbc:mysql:///jdbcdemo?useSSL=false", "root", "123456");
12 //        3.获取语句对象
13         Statement statement = con.createStatement();
14         
15 //        4.执行SQL
16         statement.executeUpdate(sql);
17         
18 //        5.释放资源close()
19         statement.close();
20         con.close();
21         

 

原文:http://www.cnblogs.com/bosskaiche/p/7470294.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!