javaWeb第一课

处理CLOB数据

实际开发中,CLOB用于存储大文本数据,但是,对MySQL而言,
大文本数据的存储是用TEXT类型表示的。

处理BLOB数据

BLOB类型的操作与CLOB类似,只是BLOB专门用于存放二进制数据,
如 图片,电影等。

数据库的操作

使用Connection来创建一个CallableStatement对象

''package com.java.chap01;

import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Types;

public class Example03 {

    public static void main(String[] args) {
        CallableStatement cstmt=null;
        Connection conn=null;

        //通过DriveryManager获取数据连接
        String url="jdbc:mysql://localhost:3306/db_user";
        String username="root";
        String password="123456";

        //注册数据库的驱动
        try {
            Class.forName("com.mysql.jdbc.Driver");
            conn = DriverManager.getConnection(url, username, password);
            //使用Connection来创建一个CallableStatement对象
            cstmt=conn.prepareCall("t_user2(?,?,?)");
            cstmt.setInt(1, 4);
            cstmt.setInt(2, 5);
            //注册CallableStatement的第三个参数为int类型
            cstmt.registerOutParameter(3,Types.INTEGER);
            //执行存储过程
            cstmt.execute();
            System.out.println("执行的结果是:"+cstmt.getInt(3));
        } catch (ClassNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (SQLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        finally{
            if(cstmt!=null){

                    try {
                        cstmt.close();
                    } catch (SQLException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
            }
            if(conn!=null){
                try {
                    conn.close();
                } catch (SQLException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }
        }
    }
}''