Actual solution for abnormal Oracle access

Source: Internet
Author: User

The following articles mainly introduce how to use Java to access Oracle exceptions through JDBC. We all know that Java accesses Oracle exceptions through JDBC often cause a lot of inconvenience in actual operation, the following article describes solutions to Oracle Character Set garbled characters.

1. The connection is very slow. An Oracle exception occurs when the select Operation is executed after the connection is successful:

 
 
  1. Exception in thread "main" java.sql.SQLException: ORA-00600:  

Internal error code, parameter:

 
 
  1. [ttcgcshnd-1], [0], [], [], [], [], [], [] 

Solution: Use jdbc \ lib \ classes12.jar in the oracle installation directory.

2. When setString (I, s) of PreparedStatement is used:

Java. SQL. SQLException: The data size exceeds the maximum value of this type: 3000

The value following is not in size, and it is related to the size of s.

Table Structure

 
 
  1. create table test(  
  2. name char(32),  
  3. addr varchar(3000)   

The same is true for varchar2.

)

Solution: Use setCharacterStream

 
 
  1. import java.sql.*;  
  2. import java.io.*;  
  3. import java.util.*;  
  4. /**  

Oracle Testing

 
 
  1. * @ Author kingfish
  2. * @ Version 1.0
  3. */
  4. Public class TestOra {
  5. Public static void testORACLE (){
  6. String url = "jdbc: oracle: thin :@ localhost: 1521: oradb ";
  7. String username = "system ";
  8. String password = "manager ";
  9. Connection conn = null;
  10. Try {
  11. Class. forName ("oracle. jdbc. driver. OracleDriver ");
  12. Conn = DriverManager. getConnection (url, username, password );
  13. }
  14. Catch (Exception e ){
  15. E. printStackTrace ();
  16. Return;
  17. }
  18. Char [] carray = new char [1000];
  19. Arrays. fill (carray, 'I ′);
  20. String s = new String (carray );
  21. Try {
  22. PreparedStatement pst = conn. prepareStatement (
  23. "Insert into test (name, addr) values (?,?) ");
  24. Pst. setString (1, "kingfish ");
  25. Pst. setCharacterStream (2,
  26. New InputStreamReader (new ByteArrayInputStream (s.
  27. GetBytes (), s. length ());
  28. Pst. setString (2, s );

Oracle exception

 
 
  1. pst.execute();  
  2. Statement st = conn.createStatement();  
  3. ResultSet r = st.executeQuery("SELECT * from test");  
  4. while (r.next()) {  
  5. s = r.getString(2);  
  6. System.out.println("len=" + s.length());  
  7. System.out.println("value=" + s);  
  8. }  
  9. r.close();  
  10. st.close();  
  11. conn.close();  
  12. }  
  13. catch (Exception e) {  
  14. e.printStackTrace();  
  15. }  
  16. }  
  17. /**  

Test

 
 
  1. * @param args String[]  
  2. */  
  3. public static void main(String[] args) {  
  4. testORACLE();  
  5. }  

The above content is an introduction to how to use Java to access Oracle exceptions through JDBC. I hope you will gain some benefits.

Article by: http://www.programbbs.com/doc/class10-1.htm

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.