H5W3
当前位置:H5W3 > 其他技术问题 > 正文

JAVA链接DB2数据库的例子

package com.wisdom;import java.lang.StringBuffer;import java.sql.Connection;import java.sql.PreparedStatement;import java.sql.DriverManager;import java.sql.*;import com.wisdom.base.DateUtil;public class Test{    public Test()    {    }    public static void main(String[] args)    {        Test test = new Test();        Connection conn = null;        try        {            Class.forName(“com.ibm.db2.jcc.DB2Driver”);            conn = DriverManager.getConnection(                “jdbc:db2://192.168.0.93:50000/CPICSMS”, “administrator”,                “rose”);//         test.save(conn);        }        catch (SQLException ex)        {            ex.printStackTrace();        }        catch (ClassNotFoundException ex)        {        }        finally        {            try            {                if (conn != null)                {                    conn.close();                }            }            catch (SQLException ex1)            {            }        }    }    private void save(Connection conn)    {        if (conn == null)            return;        PreparedStatement pstmt = null;        StringBuffer sb = new StringBuffer(“”);        sb.append(“insert into SM_PrioritySend_SM_List(ServiceID, SMContent, SendTarget, Priority, RCompleteTimeBegin,”)            .append(            ” RCompleteTimeEnd, RCompleteHourBegin, RCompleteHourEnd, RequestTime, RoadBy,”)            .append(            “SendTargetDesc,OgIdentity, FeeValue, LinkID, PAD1, PAD2, PAD3, PAD4, PAD5)”)            .append(” values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)”);        String sql = sb.toString();        try        {            pstmt = conn.prepareStatement(sql);            for (int i=0;i<2000;i++ ) {                pstmt.setString(1, “111”);                pstmt.setString(2, “12121”’中文中文中文中文中文中文中文中文中文中文中文中文中文中文中文中文中文中文中文中文中文中文中文”’2″);                pstmt.setString(3, “13840015338”);                pstmt.setInt(4, 1);                pstmt.setDate(5, DateUtil.getCurrentDate());                pstmt.setDate(6, DateUtil.getCurrentDate());                pstmt.setInt(7, 1);                pstmt.setInt(8, 1439);                pstmt.setTimestamp(9, DateUtil.getCurrentTimestamp());                pstmt.setInt(10, 1);                pstmt.setString(11, “|SRZF|100|12|||”);                pstmt.setString(12, “10000”);                pstmt.setFloat(13, 0);                pstmt.setString(14, “sadfasfd”);                pstmt.setString(15,  “sadfasfd”);                pstmt.setString(16,  “sadfasfd”);                pstmt.setString(17,  “sadfasfd”);                pstmt.setString(18,  “sadfasfd”);                pstmt.setString(19,  “sadfasfd”);                pstmt.executeUpdate();            }        }        catch (SQLException ex)        {            ex.printStackTrace();        }        finally        {            try            {                if (pstmt != null)                {                    pstmt.close();                }            }            catch (SQLException ex1)            {            }        }    }}

本文地址:H5W3 » JAVA链接DB2数据库的例子

评论 0

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址