赞
踩
package aboutCSDN; import java.sql.Connection; import java.sql.DriverManager; import java.sql.SQLException; import java.sql.Statement; import com.mysql.jdbc.Driver; public class csdnDemo002 { public static void main(String[] args) throws SQLException { //加载驱动 DriverManager.registerDriver(new Driver()); //获取连接 Connection connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/database", "root", "password"); System.out.println("连接成功"); //执行增删改查 //编写sql语句 //String sql="delete from szx666.szx678 where class_id=4"; String sql = "insert into szx666.szx678(class_id, 姓名, 性别, 年龄, 学号, m_成绩) VALUES (15,'王小明','男',19,123456789,78)"; //获取执行sql语句的命令对象 Statement statement = connection.createStatement(); //使用命令对象执行sql语句(增删改) int update = statement.executeUpdate(sql); //处理执行结果 System.out.println(update>0?"success":"failure"); //关闭连接 statement.close(); connection.close(); } }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。