第23课JDBC编程(下)1.docVIP

  • 1
  • 0
  • 约 76页
  • 2016-08-21 发布于重庆
  • 举报
第23课JDBC编程(下)1

JDBC编程(下) 内容概要 对数据库进行SQL语句进行基本操作 预编译语句 使用事务 事务的级别控制 使用存储过程 操作元数据 可滚动的和可更新的结果集 批处理更新 字符大对象CLOB 二进制大对象BLOB JDK5新特性 对数据库进行SQL语句进行基本操作 创建表: 使用JDBC创建数据库表的步骤为: 1,Creating JDBC Statements 2,Executing Statements 3,Entering Data into a Table 请看下列: import java.sql.Connection; import java.sql.Statement; public class CreateTable { public CreateTable() { super(); } public static void main(String[] args) { Connection con=null; try{ //通过连接池来获得一个连接 con=DBCon.getConnectionFromPooledDataSource(jdbcPool/mydatasource); //创建语句对象 Statement st=con.createStatement(); //创建表的SQL语句 String sql=create table student(id int,name char(30),age int); //执行完SQL语句的结果 boolean b=st.execute(sql); //true if the first result is a ResultSet object; //false if it is an update count or //there are no results if(b==false) System.out.println(create success); else System.out.println(create fail); }catch(Exception e){ e.printStackTrace(); }finally{ try{ if(con!=null)//用完连接后,要关闭释放 con.close(); }catch(Exception e){ e.printStackTrace(); } } } } 下面给表插入值: import java.sql.Connection; import java.sql.Statement; public class InsertValues { public InsertValues() { super(); // TODO Auto-generated constructor stub } /** * @param args */ public static void main(String[] args) { Connection con=null; try{ //通过连接池来获得一个连接 con=DBCon.getConnectionFromPooledDataSource(jdbcPool/mydatasource); //创建语句对象 Statement st=con.createStatement(); //给student表插入值的SQL语句 String sql=insert into student values(1,andy,47)+ insert into student values(2,jacky,53)+ insert into student values(3,周润发,51)+ insert into student values(4,谢贤,60); //执行完SQL语句的结果 boolean b=st.execute(sql); //true if the first result is a ResultSet object; //false if it is an update count or //there are no results if(b==false) System.out.println(insert success);

文档评论(0)

1亿VIP精品文档

相关文档