Java: mysql-connector-java

java -cp ".;./mysql-connector-java-8.0.28.jar" zak.Zak

https://stackoverflow.com/questions/2839321/connect-java-to-a-mysql-database

 

复制代码
package zak;


import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;

public class Zak{

  public static void main(String[] args) throws SQLException, ClassNotFoundException{
    Class.forName("com.mysql.cj.jdbc.Driver");
    String url = "jdbc:mysql://localhost:3306/java?useSSL=true&serverTimezone=GMT";
    String user = "java";
    String password = "java";
    Connection connection = DriverManager.getConnection(url, user, password);
    Statement statement = connection.createStatement();

    String drop = "drop table if exists wares";
    statement.execute(drop);

    String create = "create table wares (id int, name varchar(32), price double, introduce text)";
    statement.execute(create);

    String insert = "insert into wares (id, name, price, introduce) values (5, 'rtyu', 55, 'introduce')";
    statement.execute(insert);

    statement.close();
    connection.close();
    System.out.println(url);
  }
}
复制代码

 

posted @   ascertain  阅读(223)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 单元测试从入门到精通
· 上周热点回顾(3.3-3.9)
· winform 绘制太阳,地球,月球 运作规律
历史上的今天:
2021-04-04 httpd2.4安装
2021-04-04 VMware相关的缩略语和缩略语
点击右上角即可分享
微信分享提示