briup_JDBC
连接mysql和orcle的驱动jar包
链接:https://pan.baidu.com/s/1M5RZY62UOZbfFGIwDQK6SQ
提取码:cu6e
复制这段内容后打开百度网盘手机App,操作更方便哦
package com.briup.jdbc;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
public class JdbcTest1 {
//实现初级增删改操作
public static void main(String[] args) {
try {
// 注册驱动//"jdbc:mysql://127.0.0.1:3306/数据库名?字符编码,“用户名”,“密码”"
Class.forName("com.mysql.jdbc.Driver");
try {
// 获取到连接
Connection conn = DriverManager.getConnection(
"jdbc:mysql://127.0.0.1:3306/my_database?characterEncoding=UTF-8", "root", "yue170305");
//System.out.println();
//通过连接
Statement statement = conn.createStatement();
//准备sql语句 //注意点在执行语句是和在数据库之中是一样的
//插入一条语句
String sql= "insert into my_stu values(3,'pengpeng',21,'n')";
//修改数据
String sql2="update my_stu set id=33 where name='pengpeng'";
//一次性,插入多条数据
String sql3="insert into my_stu "
+ "values"
+ "(4,'zs',1,'n'),"
+ "(5,'ls',141,'n'),"
+ "(6,'ws',11,'n')";
//删除数据
String sql4="delete from my_stu where id=33";
//一系列执行操作
//statement.execute(sql);
//statement.execute(sql2);
//statement.execute(sql3);
statement.execute(sql4);
System.out.println("操作成功!");
statement.close();
conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
}
}