当前位置: 技术问答>java相关
我要被Clob折磨疯了,请帮帮我。
来源: 互联网 发布时间:2015-08-06
本文导语: 我要将一个超长字符串存入一个Clob字段,程序如下: import java.sql.*; import java.util.*; import java.io.*; import oracle.sql.CLOB; import oracle.jdbc.driver.*; import tools.*; import DBConnectionManager.*; public class Mgr{ private DBConnection...
我要将一个超长字符串存入一个Clob字段,程序如下:
import java.sql.*;
import java.util.*;
import java.io.*;
import oracle.sql.CLOB;
import oracle.jdbc.driver.*;
import tools.*;
import DBConnectionManager.*;
public class Mgr{
private DBConnectionManager connMgr;
private Connection conn = null;
private PreparedStatement pstmt = null;
private Statement stmt = null;
private ResultSet rs = null;
private Tools tool = new Tools();
private String sql = "";
private boolean result = false;
public Mgr()
{
connMgr = DBConnectionManager.getInstance();
conn=connMgr.getConnection("idb");
if (conn == null)
{
System.out.println("不能获取数据库连接");
}
}
public boolean addInit(int id)
{
result = false;
try
{
sql ="INSERT INTO tap (id,description)";
sql += "VALUES(tap_seq.nextval,?)";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, "empty_clob()");
pstmt.executeUpdate();
conn.commit();
pstmt.close();
result = true;
}
catch (Exception e)
{
result = false;
e.printStackTrace();
}
finally
{
connMgr.freeConnection("idb",conn);
return result;
}
}
public boolean addStamp(int id, String description)
{
result = false;
try
{
sql = "UPDATE tap SET description=?";
sql += " WHERE id=" + id;
OraclePreparedStatement opstmt =
(OraclePreparedStatement)conn.prepareStatement(sql);
opstmt.setCharacterStream(1, tool.strToBufferedReader
(description), description.length());
opstmt.execute();
conn.commit();
pstmt.close();
result = true;
}
catch (Exception e)
{
result = false;
e.printStackTrace();
}
finally
{
connMgr.freeConnection("idb",conn);
return result;
}
}
}
import java.text.*;
import java.sql.Clob;
import java.util.*;
import java.io.*;
public class Tools
{
public static BufferedReader strToBufferedReader(String str)
{
BufferedReader bufferedReader =
new BufferedReader(new StringReader(str));
return bufferedReader;
}
}
请高手指教,我到底如何将超长字符串存入Clob。
import java.sql.*;
import java.util.*;
import java.io.*;
import oracle.sql.CLOB;
import oracle.jdbc.driver.*;
import tools.*;
import DBConnectionManager.*;
public class Mgr{
private DBConnectionManager connMgr;
private Connection conn = null;
private PreparedStatement pstmt = null;
private Statement stmt = null;
private ResultSet rs = null;
private Tools tool = new Tools();
private String sql = "";
private boolean result = false;
public Mgr()
{
connMgr = DBConnectionManager.getInstance();
conn=connMgr.getConnection("idb");
if (conn == null)
{
System.out.println("不能获取数据库连接");
}
}
public boolean addInit(int id)
{
result = false;
try
{
sql ="INSERT INTO tap (id,description)";
sql += "VALUES(tap_seq.nextval,?)";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, "empty_clob()");
pstmt.executeUpdate();
conn.commit();
pstmt.close();
result = true;
}
catch (Exception e)
{
result = false;
e.printStackTrace();
}
finally
{
connMgr.freeConnection("idb",conn);
return result;
}
}
public boolean addStamp(int id, String description)
{
result = false;
try
{
sql = "UPDATE tap SET description=?";
sql += " WHERE id=" + id;
OraclePreparedStatement opstmt =
(OraclePreparedStatement)conn.prepareStatement(sql);
opstmt.setCharacterStream(1, tool.strToBufferedReader
(description), description.length());
opstmt.execute();
conn.commit();
pstmt.close();
result = true;
}
catch (Exception e)
{
result = false;
e.printStackTrace();
}
finally
{
connMgr.freeConnection("idb",conn);
return result;
}
}
}
import java.text.*;
import java.sql.Clob;
import java.util.*;
import java.io.*;
public class Tools
{
public static BufferedReader strToBufferedReader(String str)
{
BufferedReader bufferedReader =
new BufferedReader(new StringReader(str));
return bufferedReader;
}
}
请高手指教,我到底如何将超长字符串存入Clob。
|
http://www.csdn.net/expert/topic/945/945944.xml?temp=.8367578