Java accesses 2 exceptions to Oracle via JDBC

Source: Internet
Author: User
Tags error code

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

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

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

2. Occurs when using the SetString (I, s) of PreparedStatement:

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 in the back is variable, and it's about the size of S.

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 () {
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,´ 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); The exception is
Pst.execute () in this sentence;
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 ();
}
}

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.