Shan Accent

Greenhorn
+ Follow
since May 08, 2005
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
In last 30 days
0
Forums and Threads

Recent posts by Shan Accent

Hai

I created the table to insert a clob data as follows
db2 => create table ctest(datas clob(65536))
DB20000I The SQL command completed successfully.
db2 => describe table ctest

Column Type Type
name schema name Length Scale Nulls

------------------------------ --------- ------------------ -------- ----- -----
-
DATAS SYSIBM CLOB 65536 0 Yes


1 record(s) selected.

////////////////////////////////////////////

I tried the following java code to insert a clob data.

public static synchronized Connection getConnection() throws Exception {

Connection m_connectionDatabase = null;
try {
Class.forName("COM.ibm.db2.jdbc.app.DB2Driver");

// Get the connection to the database.
m_connectionDatabase = DriverManager.getConnection(
"jdbc b2:aps","","");
}catch (Exception e) {
throw new Exception("Failed to connect to the database. ", e);
}

return m_connectionDatabase;
}

public static void main(String a[]) {

File file = new File("d:\\a.txt");
InputStream fis = new FileInputStream(file);
Connection con = getConnection();
PreparedStatement pstmt = con.prepareStatement("insert into ctest values(?)");

//try 1
pstmt.setAsciiStream(1,fis,(int)file.length());

// try 2
pstmt.setCharacterStream(1,fis,(int)(file.length()));

// try 3
pstmt.setBinaryStream(1,fis,(int)(file.length()));

// try 4
byte[] b = new byte[fis.available()];
fis.read(b);
pstmt.setBytes(1, b);

// try 5
byte[] b = new byte[fis.available()];
fis.read(b);
pstmt.setString(1, new String(b));


pstmt.executeUpdate();
pstmt.close();
fis.close();
}

///////////////
Result:
////////////////

If the file size is less than 32kb, it inserted successfully.

but if more than 32kb, it throws follwing exception
COM.ibm.db2.jdbc.DB2Exception: [IBM][CLI Driver][DB2/NT] SQL0352N An unsupported SQLTYPE was encountered in position "1" of the input list (SQLDA). SQLSTATE=56084

at COM.ibm.db2.jdbc.app.SQLExceptionGenerator.throw_SQLException(Unknown Source)
at COM.ibm.db2.jdbc.app.SQLExceptionGenerator.throw_SQLException(Unknown Source)
at COM.ibm.db2.jdbc.app.SQLExceptionGenerator.check_return_code(Unknown Source)
at COM.ibm.db2.jdbc.app.DB2PreparedStatement.loadParameters(Unknown Source)
at COM.ibm.db2.jdbc.app.DB2PreparedStatement.execute2(Unknown Source)
at COM.ibm.db2.jdbc.app.DB2PreparedStatement.executeUpdate(Unknown Source)


//////////////////////
Can any body please help out to insert clob value.

Thanks in advance
V.Shan
Hai

I created the table to insert a clob data as follows
db2 => create table ctest(datas clob(65536))
DB20000I The SQL command completed successfully.
db2 => describe table ctest

Column Type Type
name schema name Length Scale Nulls

------------------------------ --------- ------------------ -------- ----- -----
-
DATAS SYSIBM CLOB 65536 0 Yes


1 record(s) selected.

////////////////////////////////////////////

I tried the following java code to insert a clob data.

public static synchronized Connection getConnection() throws Exception {

Connection m_connectionDatabase = null;
try {
Class.forName("COM.ibm.db2.jdbc.app.DB2Driver");

// Get the connection to the database.
m_connectionDatabase = DriverManager.getConnection(
"jdbc b2 ps","","");
}catch (Exception e) {
throw new Exception("Failed to connect to the database. ", e);
}

return m_connectionDatabase;
}

public static void main(String a[]) {

File file = new File("d:\\a.txt");
InputStream fis = new FileInputStream(file);
Connection con = getConnection();
PreparedStatement pstmt = con.prepareStatement("insert into ctest values(?)");

//try 1
pstmt.setAsciiStream(1,fis,(int)file.length());

// try 2
pstmt.setCharacterStream(1,fis,(int)(file.length()));

// try 3
pstmt.setBinaryStream(1,fis,(int)(file.length()));

// try 4
byte[] b = new byte[fis.available()];
fis.read(b);
pstmt.setBytes(1, b);

// try 5
byte[] b = new byte[fis.available()];
fis.read(b);
pstmt.setString(1, new String(b));


pstmt.executeUpdate();
pstmt.close();
fis.close();
}

///////////////
Result:
////////////////

If the file size is less than 32kb, it inserted successfully.

but if more than 32kb, it throws follwing exception
COM.ibm.db2.jdbc.DB2Exception: [IBM][CLI Driver][DB2/NT] SQL0352N An unsupported SQLTYPE was encountered in position "1" of the input list (SQLDA). SQLSTATE=56084

at COM.ibm.db2.jdbc.app.SQLExceptionGenerator.throw_SQLException(Unknown Source)
at COM.ibm.db2.jdbc.app.SQLExceptionGenerator.throw_SQLException(Unknown Source)
at COM.ibm.db2.jdbc.app.SQLExceptionGenerator.check_return_code(Unknown Source)
at COM.ibm.db2.jdbc.app.DB2PreparedStatement.loadParameters(Unknown Source)
at COM.ibm.db2.jdbc.app.DB2PreparedStatement.execute2(Unknown Source)
at COM.ibm.db2.jdbc.app.DB2PreparedStatement.executeUpdate(Unknown Source)


//////////////////////
Can any body please help out to insert clob value.

Thanks in advance
V.Shan
Hai every,

Please give me some idea, to do it. I created the clob field indb2 database. I don't know how to write / read the clob data.

Thanks,
V.Shan
Hai,

Can any one tell me a way to read and write the text file data or big data to db2 database using java code.

Thanks in advance...
V.shan
You can add object like below

e.g.
class simpleobj {
int a;
String name;
String value;
public void setName(...){
...
}

// Add a set and get methods
...

// Override a toString() method to return the field you want disply in
// the combo box.
public String toString(){
return name;
}
}

// In combo box
JComboBox jc = new JComboBox();
simpleobj obj = new simpleobj();
obj.setName("ss");
jc.addItem(obj);
......
// You can any object like this...

bye
19 years ago
Hai

i am working on a program were i need to pass the vector object which i am sending from java to c++

Through the jobject which i recieve in JNI , i cannot access the vector elements.

can u plz tell me how should i use it
19 years ago
Hai Kingsley Mullers ,

See the code
long Complainantidnum = String.valueOf(request.getParameter("txtidnum"));

You trying to store the string value to long variable without converting to long. What request.getParameter("txtidnum") statement actually returning ?

What type of value you want?
-------------------------
19 years ago
Hai every one,

I writen a java application . it is running backgroud. this should catch the key events when used press any key on the keyboard. So, I need a help to catch the keys in my application. Please tell me it is possible...

Thanks in advance,
Shan.
19 years ago
bur replaceAll("\\|","pipe") will work perfectly. try it... Haha.. [jumpingjoy]
19 years ago
hai Ulf Dittmer , replaceAll("\|","pipe") won't work. It will give a syntax error. try it... He..
19 years ago
you can do it the following way...

code:
----

String str = "A|B";
str = str.replaceAll("[|]","pipe");

output:
--------
ApipeB.

try it...
---------------------
Shan
19 years ago
You can get the IDE and plugins from

19 years ago
Eclipse - it is java editor. used to develope a java application, jsp,servlet and etc..., It has more futures.... ha ha..
19 years ago
one way..

You can extend the virtual memory while runing the UI.

for eg:
In command prompt

..>java -Xmx256m <class name>

------------------------------
Shanmugam
19 years ago
Peter Glass code exactly correct. - it's one way.

other way is .
In JLable or JPanel it self add What ever component you want with needed layout.

----
19 years ago