jdbc dml语句执行

来源:互联网 发布:淘宝代码有何用 编辑:程序博客网 时间:2024/06/07 01:58
import java.sql.Connection;import java.sql.DriverManager;import java.sql.ResultSet;import java.sql.SQLException;import java.sql.Statement;public class TestDML {/** * @param args * @throws ClassNotFoundException  * @throws SQLException  */public static void main(String[] args)  {// TODO Auto-generated method stubConnection conn = null;Statement statement = null;try {Class.forName("oracle.jdbc.driver.OracleDriver");conn = DriverManager.getConnection("jdbc:oracle:thin:@127.0.0.1:1521:orcl","system","123456");statement = conn.createStatement();String sql = "insert into student values(4,'shengsheng',3)";statement.executeUpdate(sql);} catch (ClassNotFoundException e) {// TODO: handle exceptione.printStackTrace();} catch (SQLException e) {// TODO: handle exceptione.printStackTrace();} finally{try {if (statement != null) {statement.close();statement = null;}if (conn != null) {conn.close();conn = null;}} catch (SQLException e) {e.printStackTrace();}}}}


原创粉丝点击