对MySQL数据库数据操作之删除

对数据库操作,删除数据库中数据


package cn.edu.hpu.operate;

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

import com.mysql.jdbc.Connection;

public class Delect {
	private static  String driver = "com.mysql.jdbc.Driver";
	private static  String url =  "jdbc:mysql://localhost:3306/数据库名";
	
	public static Connection getConn()
	{
		Connection conn = null;
		try
		{
			Class.forName(driver);
		}
		catch(ClassNotFoundException e)
		{
			e.printStackTrace();
		}
		try
		{
			conn = (Connection) DriverManager.getConnection(url,"用户名","密码");
			
		}
		catch(SQLException e)
		{
			e.printStackTrace();
		}
		return conn;
	}
	public static void main(String[] args) {
		
		int m=0;//定义一个整数
		String sql = "delete from student where s_id=对应要修改数据的s_id的值";
		Connection cnm = getConn();
		
		try
		{
			Statement stmt = cnm.createStatement();
			m = stmt.executeUpdate(sql);
		}
		catch(SQLException e)
		{
			e.printStackTrace();
		}
		System.out.println(m);//输出1表示删除成功
		}
}



你可能感兴趣的:(对MySQL数据库数据操作之删除)