Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

SQL syntax

Posted on 2001-09-03
11
Medium Priority
?
357 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

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 80 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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
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…
This video teaches viewers about errors in exception handling.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Suggested Courses

604 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