1. 連接非常慢, 連接成功後執行select操作出現異常:
Exception in thread "main" java.sql.SQLException: ORA-00600: 內部錯誤代碼,參數: [ttcgcshnd-1], [0], [], [], [], [], [], []
解決: 使用oracle安裝目錄下的jdbc\lib\classes12.jar後正常.
2. 使用PreparedStatement的setString(i, s)時出現:
可以參考帖子:http://community.csdn.net/Expert/topic/3936/3936672.xml?temp=.2879145
java.sql.SQLException: 數據大小超出此類型的最大值: 3000
後面那個值大小不定, 感覺與s大小有關
表結構
create table test(
name char(32),
addr varchar(3000) //varchar2也一樣
)
解決辦法: 采用setCharacterStream
-------------------------------------------------------
import java.sql.*;
import java.io.*;
import java.util.*;
/**
* oracle測試
* @author kingfish
* @version 1.0
*/
public class TestOra {
public static void testORACLE() {
String url = "jdbc:oracle:thin:@localhost:1521:oradb";
String username = "system";
String password = "manager";
Connection conn = null;
try {
Class.forName( "oracle.jdbc.driver.OracleDriver");
conn = DriverManager.getConnection(url, username, password);
}
catch (Exception e) {
e.printStackTrace();
return;
}
char[] carray = new char[1000];
Arrays.fill(carray, ´我´);
String s = new String(carray);
try {
PreparedStatement pst = conn.prepareStatement(
"insert into test(name,addr) values(?,?)");
pst.setString(1, "kingfish");
pst.setCharacterStream(2,
new InputStreamReader(new ByteArrayInputStream(s.
getBytes())), s.length());
//pst.setString(2,s); //用此句則異常
pst.execute();
Statement st = conn.createStatement();
ResultSet r = st.executeQuery("SELECT * from test");
while (r.next()) {
s = r.getString(2);
System.out.println( "len=" + s.length());
System.out.println( "value=" + s);
}
r.close();
st.close();
conn.close();
}
catch (Exception e) {
e.printStackTrace();
}
}
/**
*測試
* @param args String[]
*/
public static void main(String[] args) {
testORACLE();
}
}