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();
}
}

你可能感兴趣的:(java,oracle,jdbc)