JAVA informix临时表的操作

阅读更多
import 
java.sql.*;
public class dbPrepare
{
    dbPrepare()
    {
    }

    public void doPerpare()
    {
        String sDBDriver = "com.informix.jdbc.IfxDriver";
        String sConnStr = "jdbc:informix-sqli://10.100.56.25:8001/db0:informixserver=dbserver;DB_LOCALE=zh_CN.57357;CLIENT_LOCALE=zh_CN.57357;user=root;password=";
        Connection cn = null;
        try
        {
            //private String DbType="oracle";
            Class.forName(sDBDriver);
            cn = DriverManager.getConnection(sConnStr);
            ResultSet rs = null;
            Statement stmt = cn.createStatement();
            String sql = "begin work;";
            stmt.executeUpdate(sql);
            sql = "create temp table";
            sql += " tmp_sub_ne (int_id int,object_class int,zh_label varchar(40,20));";
            stmt.executeUpdate(sql);
            sql = "insert into tmp_sub_ne(int_id,object_class,zh_label)values(?,?,?);";
            PreparedStatement preStmt = cn.prepareStatement(sql);
            int int_id = 1;
            int object_class = 2;
            String zh_label = "it is a test";
            preStmt.setInt(1, int_id);
            preStmt.setInt(2, object_class);
            preStmt.setString(3, zh_label);
            preStmt.executeUpdate();
            sql = "commit";
            stmt.executeUpdate(sql);
            sql = "select * from tmp_sub_ne";
            rs = stmt.executeQuery(sql);
            while (rs.next())
            {
                System.out.println("int_id=" + rs.getInt("int_id") + ",object_class=" + rs.getInt("object_class") + ",zh_label=" + rs.getString("zh_label"));
            }
        }
        catch (Exception e)
        {
            System.err.println("conndb(): " + e.getMessage());
        }
    }

    public static void main(String[] args)
    {
        dbPrepare db1 = new dbPrepare();
        db1.doPerpare();
    }
}

你可能感兴趣的:(Informix,Java,SQL,Oracle,JDBC)