今天学习了c#连接MySQL
Java中有***********************Class.forName("com.mysql.cj.jdbc.Driver");//加载JDBC驱动
在c#中没有
Java中有**********************
public static String db_url = "jdbc:mysql://localhost:3306/jiuye?characterEcoding=utf-8&useSSL=false&serverTimezone=UTC&rewriteBatchedStatements=true";
public static String db_user = "root";
public static String db_pass = "123456";
Connection conn = null;
conn = DriverManager.getConnection(db_url, db_user, db_pass);
在c#中有对应类似的代码********************** "server=127.0.0.1;port=3306;database=zxw;user=root;password=123456";这里可以设置用户名,密码,数据库名称等
总而言之,c#连接mysql的过程就是:
1.string connectStr = "server=127.0.0.1;port=3306;database=zxw;user=root;password=123456";
MySqlConnection conn = new MySqlConnection(connectStr);
2. MySqlConnection conn = new MySqlConnection(connectStr);//MySqlConnection与Java中的Connection类似*********************************************************
3. conn.Open();//开启数据库
4.MySqlCommand cmd = new MySqlCommand(sql, conn);//*************这里的MySqlCommand与Java中的Connection类似,但是用法不同