Solved

SQL syntax

Posted on 2001-09-03
11
353 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
11 Comments
 

Expert Comment

by:plrf
ID: 6451314
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
ID: 6451372
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
ID: 6451378
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
The Ultimate Checklist to Optimize Your Website

Websites are getting bigger and complicated by the day. Video, images, custom fonts are all great for showcasing your product/service. But the price to pay in terms of reduced page load times and ultimately, decreased sales, can lead to some difficult decisions about what to cut.

 

Expert Comment

by:plrf
ID: 6451925
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
ID: 6473067
Please refer

                   http://groups.yahoo.com/group/xml-dbms/message/113
0
 

Author Comment

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

Expert Comment

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

  Declare

  String strA="";

 

  bye.
0
 

Author Comment

by:TLTEO
ID: 6475709

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
ID: 6682463
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
ID: 6720121
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
ID: 6783593
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

The Ultimate Checklist to Optimize Your Website

Websites are getting bigger and complicated by the day. Video, images, custom fonts are all great for showcasing your product/service. But the price to pay in terms of reduced page load times and ultimately, decreased sales, can lead to some difficult decisions about what to cut.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

707 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