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:
- Exception in thread "main" java.sql.SQLException: ORA-00600:
Internal error code, parameter:
- [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
- create table test(
- name char(32),
- addr varchar(3000)
The same is true for varchar2.
)
Solution: Use setCharacterStream
- import java.sql.*;
- import java.io.*;
- import java.util.*;
- /**
Oracle Testing
- * @ 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 );
Oracle exception
- 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();
- }
- }
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