Solved

SQL syntax

Posted on 2001-09-03
11
334 Views
Last Modified: 2010-08-05
For small size field, I use

PreparedStatement stmt = null;

sql = "UPDATE myrecord file"
         +" WHERE catalog=?";

  stmt = theConn.dbConn.prepareStatement(sql);
  stmt.setString(1, strA);
  stmt.setString(2, cataname)

this works for filed size smaller than 255 in MS ACCESS, when I refer to a string.

What if I wish to insert a file about 600 characters long.


What do I use ... stmt.set ..?? cos I am getting this error

java.lang.ArrayIndexOutOfBoundsException

.

0
Comment
Question by:TLTEO
11 Comments
 

Expert Comment

by:plrf
Comment Utility
In the database, maybe would to make changes. I am not sure that the type Ms Access'  TEXT support more that 255 characters. Verify that.

  the rest is Ok. Probe it.

  stmt = theConn.dbConn.prepareStatement(sql);
  stmt.setBytes(1, strA.getBytes());

  this would work.

  good luke.
0
 

Author Comment

by:TLTEO
Comment Utility
In MS ACCESS  I have to use memo field.  Because Text onlt support up to 255 characters.

woudl this be able to do it?

0
 

Author Comment

by:TLTEO
Comment Utility
I am getting this error

java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver]Invalid precision value

        at sun.jdbc.odbc.JdbcOdbc.createSQLException(JdbcOdbc.java:6031)
        at sun.jdbc.odbc.JdbcOdbc.standardError(JdbcOdbc.java:6188)
        at sun.jdbc.odbc.JdbcOdbc.SQLBindInParameterBinary(JdbcOdbc.java:714)
        at sun.jdbc.odbc.JdbcOdbcPreparedStatement.setBinary(JdbcOdbcPreparedSta
tement.java:2911)
        at sun.jdbc.odbc.JdbcOdbcPreparedStatement.setBytes(JdbcOdbcPreparedStat
ement.java:797)

0
 

Expert Comment

by:plrf
Comment Utility
If you field is memo, then use this


stmt = theConn.dbConn.prepareStatement(sql);
stmt.setClob(1, strA);

  that is all.



0
 
LVL 6

Expert Comment

by:kotan
Comment Utility
Please refer

                   http://groups.yahoo.com/group/xml-dbms/message/113
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

Author Comment

by:TLTEO
Comment Utility
strA must be a Clob.  How do I set a string to a Clob??
0
 

Expert Comment

by:plrf
Comment Utility
No problem. Use String (java class). The compiler won't generate  an error.

  Declare

  String strA="";

 

  bye.
0
 

Author Comment

by:TLTEO
Comment Utility

I am still getting this error when I conpile

setClob(int,java.sql.Clob) in java.sql.PreparedStatement c
annot be applied to (int,java.lang.String)
  stmt.setClob(1, strA);
      ^
I am just declaring String strA="";
0
 

Accepted Solution

by:
plrf earned 20 total points
Comment Utility
Hi.

  You have rigth!

  Ok!. I have problems with the field MEMO.

  I test change the type field from MEMO to OBJECT OLE in Access 2000, and that work for me.

  I show you:

  I created a table with tow fields CODE (Text) and DESCRIPTION (OBJECT OLE (before MEMO))

  For INSERT:

  byte[] EnBytes;
       ByteArrayOutputStream EnArray=new ByteArrayOutputStream();
        BufferedOutputStream EnBuffer=new BufferedOutputStream(EnArray);
        ObjectOutputStream out=new ObjectOutputStream(EnBuffer);
        out.writeObject(description);
        out.flush();
        EnBytes=EnArray.toByteArray();
        ByteArrayInputStream InArray=new ByteArrayInputStream(EnBytes);        
        prd = con.prepareStatement("INSERT INTO MyTable(code,description) VALUES(?,?)");
        prd.setString(1,code);
        prd.setBinaryStream(2,(InputStream)InArray,EnBytes.length);
        prd.executeUpdate();





AND FOR SELECT:


  ResultSet tabla=stm.executeQuery("SELECT * FROM MyTable");
        if (tabla.next())
        {
          Object objeto=new Object();
          byte[] EnBytes=new byte[100*1024];

          InputStream in=tabla.getBinaryStream("description");

          int size=in.read(EnBytes);
          ByteArrayInputStream InArray=new ByteArrayInputStream(EnBytes);        
         
          ObjectInputStream inn=new ObjectInputStream(InArray);
          objeto=inn.readObject();
          System.out.println(objeto.toString());    


        }
        tabla.close();

 

  That it is all

 I hope that work you!

  Please mail me the result your test!

 Thanks

  Godd luck!!

 
0
 
LVL 1

Expert Comment

by:akokchai
Comment Utility
Hi kotan,
  If I used the database specified JDBC driver instead of using JDBC-ODBC, I could avoid the error ??
0
 

Expert Comment

by:amp072397
Comment Utility
TLTEO:

You have many open questions:

http://www.experts-exchange.com/jsp/qShow.jsp?qid=20077765
http://www.experts-exchange.com/jsp/qShow.jsp?qid=20177485
http://www.experts-exchange.com/jsp/qShow.jsp?qid=20178630
http://www.experts-exchange.com/jsp/qShow.jsp?qid=20177653
http://www.experts-exchange.com/jsp/qShow.jsp?qid=20235670
http://www.experts-exchange.com/jsp/qShow.jsp?qid=20177859
http://www.experts-exchange.com/jsp/qShow.jsp?qid=20250974
http://www.experts-exchange.com/jsp/qShow.jsp?qid=20148640

To assist you in your cleanup, I'm providing the following guidelines:

1.  Stay active in your questions and provide feedback whenever possible. Likewise, when feedback has not been provided by the experts, commenting again makes them receive an email notification, and they may provide you with further information. Experts have no other method of searching for questions in which they have commented, except manually.

2.  Award points by hitting the Accept Comment As Answer button located above and to the left of that expert's comment.

3.  When grading, be sure to read:
http://www.experts-exchange.com/jsp/cmtyQuestAnswer.jsp#3
to ensure that you understand the grading system here at EE. If you grade less than an A, you must explain why.

4.  Questions that were not helpful to you should be PAQ'd (stored in the database for their valuable content?even if not valuable to you) or deleted. To PAQ or delete a question, you must first post your intent in that question to make the experts aware. Then, if no experts object after three full days, you can post a zero-point question at community support to request deletion or PAQ. Please include the link(s) to the question(s).
CS:  http://www.experts-exchange.com/jsp/qList.jsp?ta=commspt
At that point, a moderator can refund your points and PAQ or delete the question for you. The delete button does not work.

5.  If you fail to respond to this cleanup request, I must report you to the Community Support Administrator for further action.

Our intent is to get the questions cleaned up, and not to embarrass or shame anyone. If you have any questions or need further assistance at all, feel free to ask me in this question or post a zero-point question at CS. We are very happy to help you in this task!


thanks!
amp
community support moderator

2/4
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now