Java accesses 2 exceptions to Oracle via JDBC

Source: Internet
Author: User
Tags error code
oracle| Access


1. The connection was very slow, and an exception occurred while performing a select operation after the connection was successful:





Exception in thread "main" java.sql.sqlexception:ora-00600: Internal error code, parameters: [ttcgcshnd-1], [0], [], [], [], [], [], []





Resolution: Normal after using Jdbc\lib\classes12.jar under the Oracle installation directory.











2. Occurs when the setstring (I, s) of the PreparedStatement is used:





can refer to the post: http://community.csdn.net/Expert/topic/3936/3936672.xml?temp=.2879145





java.sql.SQLException: Data size exceeds this type of maximum value: 3000




The value behind the
is variable in size, and the feeling is related to s size





Table Structure





CREATE TABLE Test (





name Char (32),





addr varchar (3000)//varchar2 as well





)





Solution: Adopt Setcharacterstream

















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





/** * Oracle Test * @author Kingfish * @version 1.0 */public class Testora {public static void Testoracle () {Strin    G 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, ' I ');    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); With this sentence is abnormal 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 (); }}

















Note: The reason for this problem is estimated to be related to the implementation of setstring in Oraclepreparedstatement.











Kingfish





2005.4.14








Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.