Java Accessing Oracle through JDBC 2 exceptions

xiaoxiao2021-03-05  21

1. The connection is very slow, and the SELECT operation is exception after the connection is successful:

Exception in thread "main" java.sql.sqlexception: ora-00600: internal error code, parameter: [TTCGCSHND-1], [0], [], [], [], [], [], []

Solve: Normal after JDBC / lib / class12.jar in the Oracle installation directory.

2. When using PreparedStateMent's setString (i, s):

Photoves: http://community.9cbs.net/expert/topic/3936/3936672.xml? Temp = .2879145

Java.sql.sqlexception: Data size beyond this type of maximum: 3000

The value of the latter is uncertain, the feeling is related to the S size

Table Structure

Create Table Test

Name char (32),

Addr varchar (3000) // varchar2 is also the same

)

Solution: use setcharacterstream

Import java.sql. *; import java.io. *; import java.util. *;

/ ** * Oracle Test * @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, 'me'); string s = new string (carray); try {preparedState pst = conn.preparestatement ("Insert Into Test (name, addr) Values (?,?) "); Pst.SetString (1," kingfish ");

Pst.SetCharacterstream (2, New INPUTSTREAMREADER (new byterrayinputstream (s. getBytes ())), S.Length ());

//pst.setstring (2, s); // use this sentence to abnormally 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 ();}}

/ ** * Test * @Param args string [] * / public static void main (String [] args) {testoracle ();}}

Description: Causes of this problem are estimated to implement the implementation of SetString in OraclePreparedStatement.

Kingfish

2005.4.14

转载请注明原文地址:https://www.9cbs.com/read-35818.html

New Post(0)