import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.Statement;
import com.neusoft.java275.dao.DBUtil;
public class Update
{
public static void main(String[] args)
{
Connection con = null;
Statement stmt = null;
PreparedStatement prestmt=null;
try
{
Class.forName("oracle.jdbc.driver.OracleDriver");
con = DriverManager.getConnection("jdbc:oracle:thin:@192.168.137.23:1521:orcl", "java", "java");
stmt = con.createStatement();
int code=stmt.executeUpdate("insert into student(id,name) values(student_seq.nextval,'张阳')");
System.out.println("受影响的行数:"+code);
prestmt=con.prepareStatement("update student set name=? where name=?");
prestmt.setString(1, "张 阳_updated");
prestmt.setString(2, "张阳");
code=prestmt.executeUpdate();
System.out.println("受影响的行数:"+code);
}
catch (ClassNotFoundException e)
{
e.printStackTrace();
}
catch (SQLException e)
{
e.printStackTrace();
}
finally
{
DBUtil.closeQuietly(stmt);
DBUtil.closeQuietly(prestmt);
DBUtil.closeQuietly(con);
}
}
}
JDBC更新实例
最新推荐文章于 2021-10-25 15:17:48 发布