java 链接 mays
2021-05-28 05:01
标签:cti values upd sql for ora ati tco demo java 链接 mays 标签:cti values upd sql for ora ati tco demo 原文地址:https://www.cnblogs.com/sihaoyu/p/14788425.htmlpackage com.oracle.demo03;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
public class Demo01 {
public static void main(String[] args) throws ClassNotFoundException, SQLException {
//1.注册驱动
Class.forName("com.mysql.jdbc.Driver");
// 2.获取连接对象
String url="jdbc:mysql://localhost:3306/demo1127?characterEncoding=UTF-8";
String user="root";
String pwd="123456";
Connection conn= DriverManager.getConnection(url,user,pwd);
// 3.获取语句执行对象
Statement sta=conn.createStatement();
// 4.执行sql语句
String sql="insert into student(Sname,ssex,money) values(‘张三‘,‘男‘,100)";
int row=sta.executeUpdate(sql);
System.out.println(row);
// 释放资源(先开后关)
sta.close();
conn.close();
}
}