Java中經過JDBC訪問Oracle的2個異常

Java中經過JDBC訪問Oracle的2個異常

1. 鏈接很是慢, 鏈接成功後執行select操做出現異常:
Exceptioninthread"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大小有關
表結構
createtabletest(
namechar(32),
addr varchar(3000) //varchar2也同樣
)
解決辦法:採用setCharacterStream
--------------------------------------------------------------------------------importjava.sql.*;
importjava.io.*;
importjava.util.*;
/**
*oracle測試
*@authorkingfish
*@version1.0
*/
publicclassTestOra{
publicstaticvoidtestORACLE(){
Stringurl="jdbc:oracle:thin: @localhost :1521:oradb"; Stringusername="system"; Stringpassword="manager"; Connectionconn=null; try{ Class.forName("oracle.jdbc.driver.OracleDriver"); conn=DriverManager.getConnection(url,username,password); } catch(Exceptione){ e.printStackTrace(); return; } char[]carray=newchar[1000]; Arrays.fill(carray,′我′); Strings=newString(carray); try{ PreparedStatementpst=conn.prepareStatement( "insertintotest(name,addr)values(?,?)"); pst.setString(1,"kingfish"); pst.setCharacterStream(2, newInputStreamReader(newByteArrayInputStream(s. getBytes())),s.length()); //pst.setString(2,s); //用此句則異常 pst.execute(); Statementst=conn.createStatement(); ResultSetr=st.executeQuery("SELECT*fromtest"); 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(Exceptione){ e.printStackTrace(); } } /** *測試 *@paramargsString[] */ publicstaticvoidmain(String[]args){ testORACLE(); } }
相關文章
相關標籤/搜索