司浩宇

导航

java链接maply

public class Demo01 {
public static void main(String[] args) throws ClassNotFoundException, SQLException {
	//1.注册驱动 (这里会出现编译器异常)
	Class.forName("com.mysql.jdbc.Driver");
//	2.获取连接对象 jdbc:mysql:(固定的)localhost(本机的ip地址)3306(mysql固定段括号)demo1127(你要操作那个)
	//明确你要链接那个计算机上的库
	String url="jdbc:mysql://localhost:3306/demo1127?characterEncoding=UTF-8";
//	指定用户名
	String user="root";
//	密码
	String pwd="123456";
//	获取链接对象
//	Connection 导sql包 DriverManager.getConnection(url,user,pwd);(会抛异常)
	Connection conn= DriverManager.getConnection(url,user,pwd);
//	3.获取语句执行对象
//	Statement(选择sql包)
	Statement sta=conn.createStatement();
//	4.执行sql语句
	String sql="insert into student(Sname,ssex,money) values('张三','男',100)";
	String sql1="select*form student";
//	专门执行 增,删,改语句
	int row=sta.executeUpdate(sql);//括号是传语句
	System.out.println(row);
//	释放资源(先开后关)
	sta.close();
	conn.close();

  

package 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(); } } package 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(); } } package 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(); } } package 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(); } }

  

posted on 2021-05-19 17:17  司浩宇  阅读(49)  评论(0编辑  收藏  举报