JDBC TableModel problem with setValueAt

Hello to everyone. I have problem when I change value at cell in Table. My model makes update in DB, but in GUI the change is not visible. The change gets visible only when I reopen the Table.
public class CustomTableModel extends AbstractTableModel implements Serializable
    int                  dateTime = Types.DATE;
    Connection                con = null;
    ResultSet                  rs = null;
    ResultSetMetaData  rsMetaData = null;
    int                numColumns;
    String[]          columnNames = null;
    boolean           isUpdatable;
    Vector                   rows = new Vector();
    public CustomTableModel(Connection connect, ResultSet rset, String[] strl )
     try
         con = connect;
      String[] sNames = strl;
         rs = rset;
         rsMetaData = rs.getMetaData();
         numColumns = rsMetaData.getColumnCount();
         columnNames = new String[numColumns];
      int rowIndex;
      int columnIndex;
       if (rs.getConcurrency() == ResultSet.CONCUR_UPDATABLE)
          isUpdatable = true;
         else
          isUpdatable = false;
         for (int i = 0; i < numColumns; i++)
    if (sNames==null){
          columnNames[i] = rsMetaData.getColumnLabel(i+1);
    else
      columnNames = sNames;
         while(rs.next())
          Vector tempRow = new Vector(numColumns);
          for (int i = 0; i < numColumns; i++)
              switch(rsMetaData.getColumnType(i+1))
              .............. TYPES....
         } // end for loop
          rows.add(tempRow);
         } // end while loop
     }My method setValueAt
public void setValueAt(Object aValue, int rowIndex, int columnIndex)
     try
        Object oldValue = getValueAt(rowIndex,columnIndex);
         if (oldValue == null && aValue == null)
          return;
         // can use equals() only if oldValue is not null
         if (oldValue != null)
          if (oldValue.equals(aValue))
              return;
         // JTable is 0 based while ResultSet is 1 based
         rs.absolute(rowIndex+1);
         updateResultSet(rs, aValue, rowIndex, columnIndex);
         rs.updateRow();
         con.commit();
         Vector aRow = (Vector)rows.elementAt(rowIndex);
            aRow.setElementAt(aValue, columnIndex);
       fireTableCellUpdated(rowIndex, columnIndex);
     catch (SQLException ex)
         ExceptionEvent event = new ExceptionEvent(this, ex.getMessage());
         fireExceptionGenerated(event);
         try
          con.rollback();
         catch (SQLException ex2)
          event = new ExceptionEvent(this, ex2.getMessage());
          fireExceptionGenerated(event);
     catch (Exception ex)
         ExceptionEvent event = new ExceptionEvent(this, ex.getMessage());
         fireExceptionGenerated(event);
    }Thanks in advance.

import java.io.*;
import java.sql.*;
import java.text.*;
import java.util.*;
import javax.swing.*;
import javax.swing.table.*;
public class TableModelDemo extends javax.swing.JFrame {
    public TableModelDemo() {
        initComponents();
        connectDatabase();
        CustomTableModel model = new CustomTableModel();
        model.init(conn,rs,null);
        jTable1.setModel(model);
    private void connectDatabase(){
        try{
            DriverManager.registerDriver(new com.sybase.jdbc2.jdbc.SybDriver());
        }catch (Exception ex){
            ex.printStackTrace();
        conn=null;
        try{
            conn = DriverManager.getConnection("jdbc:sybase:Tds:prdfs4:2638","dba","sql");
        }catch (Exception ex){
            System.out.println("Connection refused");
        try {
            if(conn!=null){
                Statement stmt = conn.createStatement();
                String query ="SELECT ANA_LED_BASE_FORGN_CURY, ANA_AXIS_CODE, ANA_ACC_NUM, ANA_LED_TXT FROM ana_ledger " +
                        "where CMPY_CODE='06-LV   ' and JRNL_CODE='SFA  ' and ANA_LED_DOC_NUM=0008170";
                rs = stmt.executeQuery(query);
        } catch (SQLException sqe) {
            String message = sqe.getMessage();
            JOptionPane.showMessageDialog( null, message );
    private void initComponents() {
        jScrollPane1 = new javax.swing.JScrollPane();
        jTable1 = new javax.swing.JTable();
        jToolBar1 = new javax.swing.JToolBar();
        jButton1 = new javax.swing.JButton();
        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("change value at cell in Table");
        jScrollPane1.setViewportView(jTable1);
        getContentPane().add(jScrollPane1, java.awt.BorderLayout.CENTER);
        jToolBar1.setFloatable(false);
        jButton1.setText("change value at cell in Table");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
        jToolBar1.add(jButton1);
        getContentPane().add(jToolBar1, java.awt.BorderLayout.NORTH);
        java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
        setBounds((screenSize.width-790)/2, (screenSize.height-327)/2, 790, 327);
    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
        String val = JOptionPane.showInputDialog("change value at cell in Table","TEST,1,1");
        String val2[] = val.split(",");
        jTable1.setValueAt( val2[0],Integer.parseInt(val2[1]),Integer.parseInt(val2[2]) );
    public static void main(String args[]) {
                new TableModelDemo().setVisible(true);
    private javax.swing.JButton jButton1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTable jTable1;
    private javax.swing.JToolBar jToolBar1;
    private ResultSet rs ;
    private Connection conn;
class CustomTableModel extends DefaultTableModel implements Serializable {
    int                  dateTime = Types.DATE;
    Connection                con = null;
    ResultSet                  rs = null;
    ResultSetMetaData  rsMetaData = null;
    int                numColumns;
    String[]          columnNames = null;
    boolean           isUpdatable;
    Vector                   rows = new Vector();
    public void init(Connection connectToDatabase, ResultSet rset, String[] strl ) {
        try {
            con = connectToDatabase;
            String[] sNames = strl;
            rs = rset;
            rsMetaData = rs.getMetaData();
            numColumns = rsMetaData.getColumnCount();
            columnNames = new String[numColumns];
            int rowIndex=0;
            int columnIndex;
            if (rs.getConcurrency() == ResultSet.CONCUR_UPDATABLE) {
                isUpdatable = true;
            } else {
                isUpdatable = false;
            for (int i = 0; i < numColumns; i++) {
                if (sNames==null){
                    columnNames[i] = rsMetaData.getColumnLabel(i+1);
                } else {
                    columnNames = sNames;
            while(rs.next()) {
                Object[] rowData = new Object[numColumns];
                addRow( rowData );
                Vector tempRow = new Vector(numColumns);
                for (int i = 0; i < numColumns; i++) {
                    if( rowIndex==0 ){
                        addColumn( columnNames[i] );
                    setValueAt( rs.getString(i+1), rowIndex, i );
                    //                    switch(rsMetaData.getColumnType(i+1))
                    //                    .............. TYPES....
                } // end for loop
                rows.add(tempRow);
                rowIndex++;
            } // end while loop
        }catch(Exception ex){
            ex.printStackTrace();
    public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
        super.setValueAt( aValue, rowIndex, columnIndex );
        try {
            Object oldValue = getValueAt(rowIndex,columnIndex);
            if (oldValue == null && aValue == null) {
                return;
            // can use equals() only if oldValue is not null
            if (oldValue != null) {
                if (oldValue.equals(aValue)) {
                    return;
            // JTable is 0 based while ResultSet is 1 based
            //            rs.absolute(rowIndex+1);
            //            updateResultSet(rs, aValue, rowIndex, columnIndex);
            //            rs.updateRow();
            //            con.commit();
            //        Vector aRow = (Vector)rows.elementAt(rowIndex);
            //        aRow.setElementAt(aValue, columnIndex);
            //            fireTableCellUpdated(rowIndex, columnIndex);
            //        } catch (SQLException ex) {
            //            ExceptionEvent event = new ExceptionEvent(this, ex.getMessage());
            //            fireExceptionGenerated(event);
            //            try {
            //                con.rollback();
            //            } catch (SQLException ex2) {
            //                event = new ExceptionEvent(this, ex2.getMessage());
            //                fireExceptionGenerated(event);
        } catch (Exception ex) {
            //                    ExceptionEvent event = new ExceptionEvent(this, ex.getMessage());
            //                    fireExceptionGenerated(event);
}

Similar Messages

  • Oracle 8.1.5 JDBC driver problem with LONGVARCHAR

    Hi, I'm having problem with 8.1.5 release on Solaris with the
    JDBC type 4 driver (thin). If I create the following table
    create table test1 (col1 NUMBER, col2 LONG);
    Using JDBC driver to insert into the second column any string
    longer than 4000 characters causing run time exception. The type2
    driver works fine, but type2 is slow.
    String sql = "insert into test1 (col1, col2) values (1099,?)";
    PreparedStatement stmt ;
    stmt = conn.prepareStatement(sql);
    // create a string with very long value , bigger than 4096
    stmt.setString(1,string);
    stmt.executeUpdate();
    runtime exception:
    java.sql.SQLException: Data size bigger than max size for this
    type
    at java.lang.Throwable.<init>(Compiled Code)
    at java.lang.Exception.<init>(Compiled Code)
    at java.sql.SQLException.<init>(Compiled Code)
    at oracle.jdbc.dbaccess.DBError.check_error(Compiled
    Code)
    at oracle.jdbc.ttc7.TTCItem.setArrayData(Compiled Code)
    at
    oracle.jdbc.driver.OraclePreparedStatement.setItem(Compiled Code)
    at
    oracle.jdbc.driver.OraclePreparedStatement.setString(Compiled
    Code)
    at testi.main(Compiled Code)
    Any help is appreciated.
    Thanks
    Steve
    null

    Post the full stacktrace here
    Also you might want to post jdbc related questions to weblogic.developer.
    interest.jdbc
    Kumar
    DreamNEON wrote:
    Hello,
    the NSAPI integration works, also the JSP files.
    But I have still problems with the Jdriver for my Oracle 8.1.5.
    I get the message :
    Failed to invoke startup class
    weblogic.jdbc.common.internal.JdbcStartup=weblogic.jdbc.common.internal.JdbcStartup
    when the WebLogic Server is started.
    Any ideas or hints about that?
    Thanks in advance
    Armin

  • JDBC Resultset Problem with ORACLE 10.1.0.2

    Hello
    I have a problem with Petstore GenericCatalogDAO. java. The problem is the behaviour of the resultset object when retrieving data from the database.Below are two synareos one that
    works (when) hard coded and one that does not work when parameter values passed into the the result set.
    1. The code the WORKS.
    statement = connection.prepareStatement("select name from employee where a.name ='SMITH' order by name"
    ,ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
    resultSet = statement.executeQuery();
    resultSet.absolute(1);
    String s = resultSet.getString(1);
    The code that gives me a 'exhausted resultset' error which I think means no results
    String[] parameterValues = new String[] { "SMITH" };
    statement = connection.prepareStatement("select name from employee where a.name =? order by name ",
    ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
    for (int i = 0; i < parameterValues.length; i++) {
    statement.setString(i + 1, parameterValues);
    resultSet = statement.executeQuery();
    resultSet.absolute(1);
    String s = resultSet.getString(1);
    There is obviously a problem using these named parametevalues with these preparedstatement resultset, Does anybody know anything about this and a fix for it????
    Cheers. Roger

    Roger,
    It's probably a mistake you made when posting your code, but your query string is incorrect it should be either:
    select name from employee where name = 'SMITH' order by nameor
    select a.name from employee a where a.name = 'SMITH' order by a.nameIn other words you have prefixed a column with a table alias but have not indicated a table alias in the query.
    Also, shouldn't your code be:
    for (int i = 0; i < parameterValues.length; i++) {
        statement.setString(i + 1, parameterValues[ i ]);
    }Or was the "[ i ]" part giving you trouble? (Since "[ i ]" -- without the spaces -- is treated as a text-formatting tag.)
    While I didn't try your specific query, I have no problem using "PreparedStatment"s with parameters.
    What is your environment? Mine is:
    Oracle 10g (10.1.0.4) database on Linux (Red Hat)
    JDK 1.4.2
    ojdbc14.jar JDBC driver (latest version)
    Good Luck,
    Avi.

  • JDBC performance problem with Blob

    Hi,
    I've some performance problem while inserting Blob in an Oracle
    8i database. I'm using JVM 1.17 on HP-UX 11.0 with Oracle thin
    client
    The table I used contains only two columns : an integer (the
    primary key) and a blob.
    First I insert a row in the table with an empty_blob()
    Then I select back this row to get the blob
    and finally I fill in the blob with the data.
    But it takes an average 4.5 seconds to insert a blob of 47 Kb.
    Am I doing something wrong?
    Any suggestion or hint will be welcome.
    Thanks in advance
    Didier
    null

    Don S. (guest) wrote:
    : Didier Derck (guest) wrote:
    : : Hi,
    : : I've some performance problem while inserting Blob in an
    Oracle
    : : 8i database. I'm using JVM 1.17 on HP-UX 11.0 with Oracle
    thin
    : : client
    : : The table I used contains only two columns : an integer (the
    : : primary key) and a blob.
    : : First I insert a row in the table with an empty_blob()
    : : Then I select back this row to get the blob
    : : and finally I fill in the blob with the data.
    : : But it takes an average 4.5 seconds to insert a blob of 47
    Kb.
    : : Am I doing something wrong?
    : : Any suggestion or hint will be welcome.
    : : Thanks in advance
    : : Didier
    : In our testing if you use blob.putBytes() you will get better
    : performance. The draw back we found was the 32k limit we ran
    in
    : to. We had to chunk things larger than that and make calls to
    : the append method. I was dissappointed in Oracle's phone
    support
    : on what causes the 32k limit. In addition the getBytes() for
    : retrieve doesn't seem to work. You'll have to use the
    : InputStream for that. Oh, and FYI. We ran into a 2k limit on
    : putChars() for CLOB's.
    the thin drivers currently use the package "dbms_lob" behind the
    scenes while the jdbc oci 815 drivers and higher uses the native
    oci calls which makes them much faster.
    there also is a 32k limit on pl/sql stored procedures/functions
    for parms.
    you may have run into that.
    null

  • Jdbc:odbc problem with SqlDeveloper

    Hi Forum!
    My organization is evaluating moving to SQL Developer, the only obstacle for this is that we are running Oracle RDB on a VAX machine, RBD requires a special client driver that is able to work with ODBC, which is what we usually do, I am trying to setup a connection using an ODBC DSN with jdbc:odbc:DSNName, I tested this same JDBC URL with a small java class and it runs just fine, so the problem is that in SQL Developer I get an "Failure: -invalid connection information specified. Verify the URL format for the specified driver".
    * Has anyone been successful in configuring an ODBC connection on SQL Developer?
    * Any suggestion as to how to connect to Oracle RDB using SQL Developer on Windows XP?
    Thanks a lot!
    Ignacio

    Hi,
    My experience is the following:
    - Install Oracle SQL services 7.2 on Alpha machine.
    - Configure an OCI (SQLNET) service in SQL services layer.
    - Prepare my Rdb database 7.2 to run SQLNET (RDB_NATCONN scripts) and depending on version add users.
    - configure the SQLNET layer (TNSNAME) on client side (warning the default VLS listener port is 1527 on VMS instead 1521).
    - start SQL Developper and connect Rdb database via TNSNAME.

  • Jdbc connectivity problem with mySql

    Hello,
    Could anyone plz help me in solving this problem-
    there are total 3 databases on our site. 2 are old and the 3rd one we created after we installed the new version of mysql(4.1) . Now, we can connect thru over jsp pages to the old databases but when we connect it to the new (3rd ) one it throws the following exception-
    �Java.sql.SQLException: Due to underlying Exception : ArrayIndexOutOfBoundsException.44 Server connection failure during transaction. Attempted reconnect 3 times. Giving up �
    Though the data in the new database is same as in the first database becoz it was just created for testing purpose.
    Is this issue anything to do with the privleges in mysql .plz help........
    Regards

    is this problem related to privleges as i just checked my phpAdmin and there i found this warning-
    �Warning: Your privilege table structure seem to be older than this MySQL version!
    Please run the script mysql_fix_privilege_tables that should be included in your MySQL server distribution to solve this problem! �
    plz HELP

  • I have a problem with JDBC Realm in Tomcat/Oracle/Win XP

    I have a problem with JDBC Realm in Tomcat.
    I have attached my server.xml file located in the
    C:\Program Files\Apache Software Foundation\Tomcat 5.5\conf\server.xml
    The Problem is that when I login I get the user name and password prompt but it does not resolve.
    When I enter in the tomcat-users.xml password with memory realm uncommented it works fine.
    C:\Program Files\Apache Software Foundation\Tomcat 5.5\conf\tomcat-users.xml
    Is there a cache or something I need to reset for the JDBC Realm to work?
    I have attached my tables and contents as well...
    Did I miss something????
    Thanks
    Phil
    server.xml
    <Server port="8005" shutdown="SHUTDOWN">
    <Listener className="org.apache.catalina.mbeans.ServerLifecycleListener" />
    <Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" />
    <Listener className="org.apache.catalina.storeconfig.StoreConfigLifecycleListener"/>
    <!-- Global JNDI resources -->
    <GlobalNamingResources>
    <!-- Test entry for demonstration purposes -->
    <Environment name="simpleValue" type="java.lang.Integer" value="30"/>
    </GlobalNamingResources>
    <!-- Define the Tomcat Stand-Alone Service -->
    <Service name="Catalina">
    <!-- Define a non-SSL HTTP/1.1 Connector on port 8080 -->
    <Connector
    port="8080" maxHttpHeaderSize="8192"
    maxThreads="150" minSpareThreads="25" maxSpareThreads="75"
    enableLookups="false" redirectPort="8443" acceptCount="100"
    connectionTimeout="20000" disableUploadTimeout="true" />
    <!-- Define an AJP 1.3 Connector on port 8009 -->
    <Connector port="8009"
    enableLookups="false" redirectPort="8443" protocol="AJP/1.3" />
    <!-- Define the top level container in our container hierarchy -->
    <Engine name="Catalina" defaultHost="localhost">
    <!--
    <Realm className="org.apache.catalina.realm.MemoryRealm" />
    -->
    <Realm className="org.apache.catalina.realm.JDBCRealm"
    driverName="oracle.jdbc.driver.OracleDriver"
    connectionURL="jdbc:oracle:thin:@localhost:1521:orcl"
    connectionName="testName" connectionPassword="testPass"
    userTable="users"
    userNameCol="user_name"
    userCredCol="user_pass"
    userRoleTable="user_roles"
    roleNameCol="role_name" />
    <!-- Define the default virtual host
    Note: XML Schema validation will not work with Xerces 2.2.
    -->
    <Host name="localhost" appBase="webapps"
    unpackWARs="true" autoDeploy="true"
    xmlValidation="false" xmlNamespaceAware="false">
    </Host>
    </Engine>
    </Service>
    </Server>
    Tables
    create table users
    user_name varchar(15) not null primary key,
    user_pass varchar(15) not null
    create table roles
    role_name varchar(15) not null primary key
    create table user_roles
    user_name varchar(15) not null,
    role_name varchar(15) not null,
    primary key( user_name, role_name )
    select * from users;
    ----------------------+
    | user_name | user_pass |
    ----------------------+
    | tomcat | tomcat |
    | user1 | tomcat |
    | user2 | tomcat |
    | user3 | tomcat |
    ----------------------+
    select * from roles;
    | role_name |
    | tomcat |
    | role1 |
    select * from user_roles;
    -----------------------+
    | role_name | user_name |
    -----------------------+
    | tomcat | user1 |
    | role1 | user2 |
    | tomcat | tomcat |
    | role1 | tomcat |
    -----------------------+

    Jan 2, 2008 11:49:35 AM org.apache.coyote.http11.Http11Protocol init
    INFO: Initializing Coyote HTTP/1.1 on http-8080
    Jan 2, 2008 11:49:35 AM org.apache.catalina.startup.Catalina load
    INFO: Initialization processed in 734 ms
    Jan 2, 2008 11:49:35 AM org.apache.catalina.core.StandardService start
    INFO: Starting service Catalina
    Jan 2, 2008 11:49:35 AM org.apache.catalina.core.StandardEngine start
    INFO: Starting Servlet Engine: Apache Tomcat/5.5.9
    Jan 2, 2008 11:49:35 AM org.apache.catalina.realm.JDBCRealm start
    SEVERE: Exception opening database connection
    java.sql.SQLException: oracle.jdbc.driver.OracleDriver
         at org.apache.catalina.realm.JDBCRealm.open(JDBCRealm.java:684)
         at org.apache.catalina.realm.JDBCRealm.start(JDBCRealm.java:758)
         at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1004)
         at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:442)
         at org.apache.catalina.core.StandardService.start(StandardService.java:450)
         at org.apache.catalina.core.StandardServer.start(StandardServer.java:683)
         at org.apache.catalina.startup.Catalina.start(Catalina.java:537)
         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
         at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
         at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
         at java.lang.reflect.Method.invoke(Method.java:585)
         at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:271)
         at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:409)
    Jan 2, 2008 11:49:35 AM org.apache.catalina.core.StandardHost start
    INFO: XML validation disabled
    Jan 2, 2008 11:49:36 AM org.apache.catalina.core.StandardContext resourcesStart

  • $200 reward to solve problem with JDBC and CLOB.getCharacterOutputStream

    I'm trying to update CLOB with the getCharacterOutputStream as suggested in the example code. It works with US7ASCII DB instance but not instances in UTF8.
    I've been browsing through all the Oracle doc's and found some rather confusing statements:
    In the page at http://oradoc.photo.net/ora816/java.816/a81354/oralob2.htm#1043220
    it says: [When writing to or reading from a CLOB, the JDBC drivers perform all character set conversions for you.]
    also: [The oracle.sql.CLOB class supports all the character sets that the Oracle data server supports for CLOB types.]
    So far so good.
    In the page at http://oradoc.photo.net/ora816/java.816/a81354/oraint3.htm#1012518
    it says [The oracle.sql package supports these datatypes in several ways: CLOBs point to large fixed-width character data items (that is, characters that require a fixed number of bytes per character) and are supported by the oracle.sql.CLOB class.]
    Ooh no! Is this for real? UTF8 is variable width and does this mean it is not supported?
    Any way to get around this?
    In the page at http://oradoc.photo.net/ora816/java.816/a81358/03_pub2.htm#36009
    says [6.The mappings to oracle.sql classes are optimal because they preserve data formats and require no character-set conversions (apart from the usual network conversions). Those classes are especially useful in applications that "shovel" data between SQL and Java.]
    "No character set conversion"? Very confusing!
    I've been hammering on this CLOB/JDBC/UTF8 problem for more than a week now and I really appreciate some solutions, workarounds, or whatever help I can get. I'm running java stored procedure in 8.1.6 on Linux RH6.2.
    For your trouble, I'd pay $200 for the first guy who come up with a verifiable solution.

    This is just findings based upon your comments:
    Please refer to document Oracle8i National Language Support Guide
    Release 2 (8.1.6) from Oracle Documentation Library, Release 8.1.7
    Chapter 6 Java,
    There its clearly mention that:
    "Oracle JDBC drivers provide globalization support by allowing users to retrieve data from or insert data into a database in any character set that Oracle supports. Because Java strings are UCS2 encoded (16-bit Unicode) for JDBC programs, the target character set on the client is always UCS2. Character set conversion is required to convert data from the database character set (Db Charset) to UCS2. This applies to CHAR, LONG, CLOB, and VARCHAR2 data types; RAW data is not converted. "
    Also..please refer this...
    "oracle.sql.CLOB's method getCharacterStream() returns the contents of a CLOB as a Unicode stream."
    "The techniques that Oracle's drivers use to perform character set conversion for Java applications depend on the character set the database uses. The simplest case is where the database uses a US7ASCII or WE8ISO8859P1 character set. In this case, the driver converts the data directly from the database character set to UCS2,which is used in Java applications. "
    "If you are working with databases that employ a non-US7ASCII or non-WE8ISO8859P1 character set (for example, Japanese or Korean), then the driver converts the data, first to UTF8, then to UCS2. "
    In my case the characte-set of the database is WE8ISO8859P1 and for security reason i can't change the character set but my feeling is that if you are updating the CLob from the java client you are forming a reference of a clob in the client which is UCS2 at the Java side. Now when you are populating the clob through java.io.Writer and call the procedure to pass the reference of the clob to the procedure then I believe the JDBC will convert the UCS2 datatype of Clob to UTF8 in the database.
    You can try out the code snippet:
    package ServletGDC;
    import java.io.*;
    import java.util.*;
    import javax.servlet.*;
    import javax.servlet.http.*;
    import oracle.sql.*;
    import java.sql.*;
    import oracle.jdbc.driver.*;
    import ClassesGDC.*;
    public class testUpload extends HttpServlet {
    private String m_strMessage="";//It stores the message to be uploaded along with the Document
    Connection conn=null;
    public void doPost(HttpServletRequest req, HttpServletResponse res)
    throws ServletException, IOException {
    String strContent="";
    //res.setContentType("application/msword");
    res.setContentType("text/html");
    PrintWriter out = res.getWriter();
    try {
    CallableStatement cmt=null;
    OutputStream output=null;
    ByteArrayOutputStream byteoutput=null;
    String strDocString="";
    oracle.sql.CLOB tempClob = null;
    String strPassedFileName="";     // the file name passed in the request object
    String strStdFilename="";//the file name to be given to the best practice
    String strSaveDirectory="";     //the directory in which the bp is to be saved
    String strParamName="";//name of parameters
    String strParamValue="";//value of parameters
    int intTempVariable=0; // temporaty variable
    long lngSizeOfFileUploaded=0;//stores the size of the file which had been uploaded in the file system
    File filePathOfFileUploaded=null;//stores the path of the file uploaded to the file system
    String strQuery="";
    //ST------------checks if the user has logged in or not-----------------------
    HttpSession session=req.getSession(true);
    if(req.getContentLength()>20*1024*1024)
    throw new skip("The size of the posted content is more than 10 MB . If you have a best practice whose size is more than 1 MB please mail it to Us.");
    byteoutput = new ByteArrayOutputStream();
    MultipartParser mp = new MultipartParser(req, 20*1024*1024); // 10MB is the limit of the file to be uploaded
    Part part;//Its an abstact part which helps in retrieving information about the file and the parameters
    while ((part = mp.readNextPart()) != null) {//Reads the next part
    strParamName = part.getName();
    // the following if is executed if the part is for a parameter rather than a file
    if (part.isParam()) {
    }else if (part.isFile()) {
    // it's a file part
    m_strMessage="inside file part";
    FilePart filePart = (FilePart) part;
    strPassedFileName = filePart.getFileName();
    strContent= filePart.getContentType();
    out.println("<BR><font color=red>strPassedFileName is "+strPassedFileName+"</font>");
    if(strPassedFileName != null || !(strPassedFileName.trim().equals("")) ) {
    // the part actually contained a file
    out.println("<BR><font color=red> before forming long</font>");
    //lngSizeOfFileUploaded = filePart.writeTo(filePathOfFileUploaded);      //the statement upload the bestpractice in the
    lngSizeOfFileUploaded = filePart.writeTo(byteoutput);     //specified file path filePathOfFileUploaded.
    out.println("<BR><font color=red> after file is written into the outputstream</font>");
    else {
    throw new skip("The file name is null or it is empty space. Files in such Format are not accepted");
    }//end of else if
    }//end of while loop
    if(     lngSizeOfFileUploaded==0)     {// the size of the file uploaded is zero then the file supplied was not proper and hence exception is to be thrown
    //if(filePathOfFileUploaded.exists())
    //     filePathOfFileUploaded.delete();
    throw new skip("The File could not be uploaded,Possible reasons may be that the file is sent null or the file is corrupted");
    //END---------------the file is uploaded in the proper directory--------------------
    //res.setContentType(strContent);
    out.println("<BR><font color=red>long value is : "+lngSizeOfFileUploaded+" and content is "+strContent+"</font>");
    String strbyte= byteoutput.toString();
    byteoutput.flush();
    Class.forName("oracle.jdbc.driver.OracleDriver");
    // Establish network connection to database
    conn = DriverManager.getConnection("jdbc:oracle:thin:@pc-p32670:1521:GDCDBI","gdc_user","myuser");
    //if(conn!=null)
    out.println("<BR><font color=red>Connection formed"+conn);
    //els
    //out.println("<BR><font color=red>long value is : "+strbyte+"</font>");
    try{
    tempClob = oracle.sql.CLOB.createTemporary(conn,true, oracle.sql.CLOB.DURATION_SESSION);
    out.println("<BR><font color=red>tempClob : "+tempClob);
    tempClob.open( oracle.sql.CLOB.MODE_READWRITE);
    java.io.Writer tempClobWriter = tempClob.getCharacterOutputStream();
    // writing the string formed from the multipart file to the clob
    tempClobWriter.write(strbyte);
    if(tempClob!=null){}
    out.println("<BR><font color=red>CLOB value is : "+tempClob+"</font>");
    strQuery="{call INSERT_CLOB(?,?)}";
    cmt=conn.prepareCall(strQuery);
    cmt.setString(1,strPassedFileName);
    cmt.setClob(2,tempClob);
    cmt.registerOutParameter(2,java.sql.Types.CLOB);
    cmt.execute();
    tempClobWriter.flush();
    tempClobWriter.close();
    tempClob.freeTemporary();
    //res.setContentType(strContent);
    //strDocString.toString();
    out.println("<BR><font color=red>bob is "+strbyte+"</font>");
    tempClob.close();
    }catch(Exception e){
    tempClob.close();
    out.println("<font color=blue> Error is :"+e.getMessage()+"</font>");
    //e.printStackTrace(out);
    cmt.close();
    //out.println("<BR><font color=red><h2><b>SUCCESS</h2></font>");
    //res.sendRedirect("../test/showfile.jsp?contentype="+strContent.trim()+"");
    }catch(Exception e){
    java.util.Date d = new java.util.Date();
    String s =d.toString();
    out.println("<font color=blue> Error is :"+e.getMessage()+"</font>");
    //e.printStackTrace(out);
    }finally{
    try{
    if(conn!=null)
    conn.close();
    }catch(Exception e){
    out.println("<font color=blue> Error is :"+e.getMessage()+"</font>");
    }// end of finally
    } //end of doPost
    } //end of class
    in the Procedure you will be inserting/updating the clob in a table with the reference clob in the out parameter of the procedure
    Thanks.

  • Problem with Java 5 and Oracle 10g JDBC driver

    Hi All,
    Currently we upgrade our web application to Java 5 and Oracle 10.2 JDBC driver. And we encountered a bug, when the user entered the information through UI and data didn't store into database (Oracle 9i). The problem is that this bug is not happend so often maybe once a day and this did not happen before we upgraded to Java 5 and Oracle 10.2 JDBC driver. Does anyone encounter the same problem ? Is this Java 5 problem or Oracle JDBC driver problem ?
    Thanks,

    sounds like a database problem...
    Are you using a driver version that's supported for your database engine?
    What else did you change? We once ran into a major bug in our application that had for 5 years been masked by performance problems in our hardware and infrastructure.
    Once those were resolved the bug showed itself and caused tens of thousands of records to be erroneously inserted into our database every day.
    It's certainly NOT a problem with your JVM (if it's a decent one, like the Sun implementation).
    So it's either your database, your driver, your network (dropping packets???), or your application.
    The upgrade may just have exposed something that was already there.

  • Problem with JDBC and Tomcat

    I don't know where the problem originate, the only thing in my memory is that the program worked very well on my PC yesterday, but today, without even slightest change, it doesn't work anymore. As to debug it, I simplified the codes to the least, but it still refuse to work. I was beaten down by this problem totally, and cannot make out any solution for it, so, I come here, hoping to find a warrior to kill this damned bug for me.
    My program is a Servlet, but for the purpose of debugging, I have recode it to an Application/Servlet. When run as a application, I can get the result expected, but as a Servlet, :-(, maybe you should see it by yourself. My server software is Tomcat 4.1.15, and the JDK version is 1.4.0. To excute this program, you should add Data Source "Test" to ODBC.
    ///////////////////////code begins/////////////////////////
    import java.sql.*;
    import javax.servlet.*;
    import javax.servlet.http.*;
    import java.io.*;
    import java.util.*;
    public class Ex extends HttpServlet
         int ErrorType = 0;
         String err = new String("");
         public static void main(String args[]) throws Exception{
              Ex cEx = new Ex();
              cEx.init();     
              System.out.println(cEx.ErrorType);     
         public void init() {
              String url = "jdbc:odbc:Test";
              ErrorType = 3;     //passed
              try{
                   Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
              } catch (ClassNotFoundException e) {
                   e.printStackTrace();
                   ErrorType = 1; //trapped in Class.forName
              try{
                   Connection c = DriverManager.getConnection(url);
              } catch (SQLException e) {
                   e.printStackTrace();
                   ErrorType = 2; //trapped in DriverManager.getConnection
                   err = e.getMessage();
         public void service(HttpServletRequest req, HttpServletResponse res)
                   throws IOException {
              res.setContentType("text/html; charset=GB2312");
              PrintWriter out = res.getWriter();
              out.println("Success " + "<p>" + ErrorType + "<p>" +err);
              out.close();
    //////////////////////////code ends///////////////////////////////
    The result from the Servlet tell me that the problem occurred within the connection process, I don't know who should be responsible to this - Tomcat or JDBC?

    If you could print the exception that you got then that would help :) In the mean time, I could make a guess. It is unlikely that your application server (in this case, Tomcat) is blocking connections from your servlet. So the problem is either with JDBC directly or with the underlying datasource. It seems unlikely that it is JDBC given that you have stated that the code has not changed and it works in application form.
    My guess would be that you are coming up against some sort of security constraint (eg: your DBMS is letting you log in from one IP but not another?, your Java plug-in security policy is disallowing the connection?). It's hard to say.
    But if it works as an application but not via a servlet then you could try putting this in your java.policy file, which is located in the directory where your plug-ins are installed (eg: "C:\Program Files\Java\<version>\lib\security\") on Windows systems;
    permission java.net.SocketPermission "bend xp:1099", "listen,connect,accept";
    Try that, see if it works :)
    Ben

  • Problem with JDBC results calling simple stored procedure in VC 7.0

    Hi all,
    I am building a simple VC model which calls a stored procedure on a JDBC database. I have created the system in the portal, defined the alias and user mapping, the connection test is fine and the VC "find data" lists my bespoke stored procedure.
    The stored procedure is :
    CREATE PROCEDURE dbo.dt_getBieUsers
    AS
    select * from dbo.emailuserlink
    GO
    When I test it using query analyser, it returns 3 records each with the two fields I expect - user and email address.
    I drag the model onto the workspace in VC and create an input form ( with just a submit button ). i drag the result port out to create a table. This has no fields in it.
    I build and deploy as flex and the app runs, I click the submit button and SUCCESS! I get 3 records in my table each with 2 fields. The data is all correct. The problem with this is the fields are determined at runtime it seems.
    I go back to the table and add 2 columns "email" and "address".
    i build and deploy and run the app. Again I get 3 records, but this time the contents of all of the rows is not data, but "email" and "address". The data has been replaced by the header texts in all of the rows.
    Can anyone help? Why isn't the data being put in my columns as I would expect?
    I tried to build and deploy the app as Web Dynpro rather than Flex to see if it was a bug in Flex. The application starts but when I click the submit button to run the JDBC stored procedure I get a 500 Internal Server Error
    com.sap.tc.wd4vc.intapi.info.exception.WD4VCRuntimeException: No configuration is defined for the entry JDBCFunction
        at com.sap.tc.wd4vc.xglengine.XGLEngine.createComponentInternal(XGLEngine.java:559)
        at com.sap.tc.wd4vc.xglengine.XGLEngine.getCompInstanceFromUsage(XGLEngine.java:362)
        at com.sap.tc.wd4vc.xglengine.XGLEngine.getCompInstance(XGLEngine.java:329)
        at com.sap.tc.wd4vc.xglengine.wdp.InternalXGLEngine.getCompInstance(InternalXGLEngine.java:167)
        at com.sap.tc.wd4vc.xglengine.XGLEngineInterface.getCompInstance(XGLEngineInterface.java:165)
    The JDBC connection I am using has a connection URL of jdbc:sap:sqlserver://localhost;DatabaseName=BIEUSERS
    and a driver class of com.sap.portals.jdbc.sqlserver.SQLServerDriver
    Can anyone solve my wierd problems?
    Cheers
    Richard

    Hi Richard,
    After you drag and drop the data service, right click on it and choose "Test data service". Then click on "Execute" and after you see the result on the right, click on "Add fields" button (inside the same window). Now you'll see that the fields are on the tabel. This is required only for JDBC data services, since this data (how the resultset is built) is not know in DT and it needs to be run firest - then analysed and only then you have to add the fields to the table).
    Regards,
    Natty

  • Problem with XML SQL  JDBC adapter

    Hello All.
    I have quite strange problem with my PI.
    Whole scenario is SOAP -> JDBC, asynchronous. Everything works fine on DEV server. After transporting objects (using CTS) to QA env I'm getting this error:
    JDBC Message processing failed, due to Error processing request in sax parser:
    No 'action' attribute found in XML document
    (attribute "action" missing or wrong XML structure)
    But document seems to be correct. I've compared it to DEV server documents - they are identical. What could be wrong??
    Document looks like this:
    <ns2:BIPMessage xmlns:ns2="http://mynamespace.com/xi/sn"
    xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <synchSlLok>
       <STATEMENTNAME>
         <SYNCH_SL_LOK ACTION="INSERT">
            <TABLE>SYNCH_SL_LOK</TABLE>
             <ACCESS>
                <ID_TRANS>22050</ID_TRANS>
                <ID_LOK>1234</ID_LOK>
                <ID_CBK>1000050911</ID_CBK>
                <NR_LOK>1234</NR_LOK>
                <OPIS_LOK>12312312312312</OPIS_LOK>
                <TYP>D</TYP>
                <OPERACJA>U</OPERACJA>
              </ACCESS>
          </SYNCH_SL_LOK>
        </STATEMENTNAME>
      </synchSlLok>
      </ns2:BIPMessage>
    TIA
    Best Regads
    Maciej

    Hi,
    i was also facing the same error few days back in a JDBC -RFC-JDBC Synchronous scenario. In that scenario, i was using 2 modules in JDBC sender module tab. It was working fine. later i change polling interval and then i started getting same error. it happened coz of sequence of Module got changed somehow.
    So please check in Receiver JDBC adapter and SOAP sender adapter CC  if anything is changed. If this scenario is working in DEV as it is then it should work after transport.
    Else have a look here
    Re: attribute "action" missing or wrong XML structure
    JDBC - No 'action' attribute found in XML document - error
    Regards
    Aashish Sinha
    Edited by: Aashish Sinha on Mar 15, 2011 10:42 AM

  • Problem with Progress DB while using to connect using JDBC Adapter

    Hi,
      I am facing Problem with Progress DB while using to connect using JDBC Adapter. I am getting the following error in auditlog file like,
    Error during database connection to the database URL  jdbc:JdbcProgress:T:156.5.31.65:2545:/mfgprodev/devbadb 
    /devsche/i_apoext.db using the  JDBC driver "com.progress.sql.jdbc.JdbcProgressDriver" : com.sap.aii.adapter.jdbc.sql.DriverManagerException: Unable to locate a suitable JDBC driver to establish a connection to URL " jdbc:JdbcProgress:T:156.5.31.65:2545:/mfgprodev/devbadb 
    /devsche/i_apoext.db "
    I tried using the following all URLs,
    1. jdbc:JdbcProgress:T:156.5.31.65:2545:i_apoext.       
    2. jdbc:JdbcProgress:T:156.5.31.65:2545:i_apoext.db     
    3.                                                      
    jdbc:JdbcProgress:T:156.5.31.65:2545:/mfgprodev/devbadb 
    /devsche/i_apoext.                                      
    4.                                                      
    jdbc:JdbcProgress:T:156.5.31.65:2545:/mfgprodev/devbadb 
    /devsche/i_apoext.db.                                  
    Can anyone please help me out in solving this issue.
    May be the cause for this is :
    1) The Wrong URL  format
    2) CLASSPATH is not setted properly..
    Can you look more into this stuff.
    Thanks,
    Soorya.

    Hi,
    To access any database fromm XI, using the JDBC adapter, the corresponding drivers have to be installed on the XI server.
    Just check this note 831162.
    Also, check this PDF to install Drivers in XI,
    https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/docs/library/uuid/3867a582-0401-0010-6cbf-9644e49f1a10

  • Beginner Has Problem With Loading JDBC Driver Using MySQL

    Hi, I am having problem with loading JDBC driver, and need your diagnotic help.
    1. I have installed MySQL (C:\mysql), created a databse (soup), and created a littel table (VIDEOS). I am able to see the table in the console:
    sql> select * from videos
    2. I have downloaded the latest version of Connector/J (mysql-connector-java-3.1.0-alpha.zip), and unzip the zip file into my C:\ directory.
    3. I copied the mysql-connector-java-3.1.0-alpha-bin.jar to the C:\j2sdk1.4.1_02\jre\lib\ext folder and it is in my CLASSPATH
    4. MySQL server is running
    C:\> C:\mysql\bin\mysqld-nt --standalone
    5. open another DOS window and use the database
    mysql>USE SOUP
    6. succesfully compiled a Java program (javac Test.java):
    import java.sql.* ;
    public class Test
    public static void main( String[] args )
    try
    Class.forName("org.gjt.mm.mysql.Driver").newInstance();
    try
    Connection con = DriverManager.getConnection( "jdbc:mysql://localhost:3306/soup" );
    try
    Statement statement = con.createStatement();
    ResultSet rs = statement.executeQuery("SELECT TITLE FROM VIDEOS");
    while ( rs.next() )
    System.out.println( rs.getString( "TITLE" ) );
    rs.close();
    statement.close();
    catch ( SQLException e )
    System.out.println( "JDBC error: " + e );
    finally
    con.close();
    catch( SQLException e )
    System.out.println( "could not get JDBC connection: " + e );
    catch( Exception e )
    System.out.println( "could not load JDBC driver: " + e );
    7. when I run the Java program (java Test), I got
    the message:
    could not load JDBC driver: java.lang.ClassNotFoundException: org.gjt.mm.mysql.Driver
    What am I missing?

    Hi,
    I missed to specify test in my last post.
    Try running your program by explicitly setting the classspath when
    running your program . java -classpath c:\mysql-connector-java-3.1.0-alpha-bin.jar test
    Make sure your jar file contains org.gjt.mm.mysql.Driver class

  • Language problem with my jdbc connection

    Hello,
    i'm having a problem with my jdbc connection.
    the problem is that i'm connecting to MS- Access db the have arabic tables, and columns, it was working fine on a windows XP environment prepared for arabic language, but when i had to move to windows vista it did not work and it gave me an exception.
    i'm using netbeans 6.1 IDE, and the exception is
    java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver]COUNT field incorrect
    at sun.jdbc.odbc.JdbcOdbc.createSQLException(JdbcOdbc.java:6957)
    at sun.jdbc.odbc.JdbcOdbc.standardError(JdbcOdbc.java:7114)
    at sun.jdbc.odbc.JdbcOdbc.SQLExecDirect(JdbcOdbc.java:3110)
    at sun.jdbc.odbc.JdbcOdbcStatement.execute(JdbcOdbcStatement.java:338)
    when i printed the select statement and the exception it gave me:
    SELECT [??? ???????], [??? ??????], [??? ?????], [??? ?????], [????? ???????????] FROM EDU_DIVISION; [Microsoft][ODBC Microsoft Access Driver]COUNT field incorrect.
    the question marks are very weird to appear!!!!!!
    here is the code:
    public void edu_branch() {
            sucpy = 0;
            eflag = 0;
            asql = "SELECT [\u0643\u0648\u062F \u0627\u0644\u062C\u0627\u0645\u0639\u0629], [\u0643\u0648\u062F \u0627\u0644\u0643\u0644\u064A\u0629], [\u0643\u0648\u062F \u0627\u0644\u0642\u0633\u0645], [\u0643\u0648\u062F \u0627\u0644\u0634\u0639\u0628\u0629], [\u0627\u0633\u0645 \u0627\u0644\u0634\u0639\u0628\u0629], [\u0627\u0633\u0645 \u0627\u0644\u0634\u0639\u0628\u0629 \u0628\u0627\u0644\u0627\u0646\u062C\u0644\u064A\u0632\u064A\u0629], [\u0627\u0644\u0643\u0648\u062F \u0627\u0644\u0645\u062E\u062A\u0635\u0631] FROM EDU_BRANCH;";
            Connection connection;
            Statement statement;
            try {
                Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
                connection = DriverManager.getConnection("jdbc:odbc:info");
                System.out.println("Connection to Access file is created...");
                statement = connection.createStatement();
                statement.execute(asql);
                System.out.println("Executing query : " + asql);
                aset = statement.getResultSet();
                if (aset != null) {
    //------------------------------Oracle operations--------------------------------------------------------------------                  
                    while (aset.next()) {
        can you help me please

    arabic language
    SELECT [??? ???????], [??? ??????], [??? ?????], [??? ?????], [????? ???????????] FROM EDU_DIVISION; >[Microsoft][ODBC Microsoft Access Driver]COUNT field incorrect.
    the question marks are very weird to appear!!!!!!It failed to understand your unicode sql.
    it was working fine on a windows XP environment prepared for arabic language, but when i had to move to windows vista it did not workStrange. Maybe you need to compare the differences of some system properties on both hosts, for instance, sun.io.unicode.encoding, file.encoding, user.region, and so on.

Maybe you are looking for

  • Project Server 2010 - Change Status Manager

    End Goal: We would like to perform this change via SQL statement - which I believe I have  I feel like I am missing something and not sure what it is. Background:  We migrated from a different product to Project Server 2010, while our team members we

  • Outlook integration

    I have just installed Adobe Reader 10.1.3. For some reason the Reader is not working with my Outlook or My Documents. Is there something I must do to integrate? I can preview the files, but cannot open them.

  • Doubt in user exit

    Hi,   I have created an enhancement spot for an include program which exists in 2 main programs.if I run it in normal flow through transaction FK01 the enhancement spot is not executing but if I keep the break point and test  the enhancement spot the

  • Seeking help to create report

    I'm hoping someone can help me. I have a report that keeps track of outages based on application. I now need to break down that report and display the percentage of availability for each application by month. If no outage occured on certain days of t

  • Why the new QuickType in iOS 8 disappear suddenly?

    Early today, the new QuickType feature in iOS 8 on my iPhone 5 worked well. However, later, this new impressive feature desapperaed all of a sudden. I cannot figure out why.