8

My code is as follows:

        PreparedStatement pstm = con.prepareStatement("insert into parameter(Parameter) values(?)");
        Array a = con.createArrayOf("TEXT",s1);
        pstm.setArray(1,a);
        pstm.executeUpdate();

The stacktrace is as follows:

   Exception in thread "main" java.sql.SQLFeatureNotSupportedException
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:525)
at java.lang.Class.newInstance0(Class.java:372)
at java.lang.Class.newInstance(Class.java:325)
at com.mysql.jdbc.SQLError.notImplemented(SQLError.java:1329)
at com.mysql.jdbc.JDBC4Connection.createArrayOf(JDBC4Connection.java:56)
at project.Project.main(Project.java:295)

Please help me in rectifying this issue. Thank you in advance.

karthikbv
  • 183
  • 1
  • 4
  • 13

1 Answers1

4

http://docs.oracle.com/javase/6/docs/api/java/sql/SQLFeatureNotSupportedException.html

It means that your mysql driver can't do that operation. Either use a different driver/database, or don't use that method.

Thomas
  • 5,074
  • 1
  • 16
  • 12
  • What other method can be used to accomplish my task? – karthikbv Apr 01 '13 at 13:38
  • You haven't listed a task. From the code, you want to insert an Array type into your database. [According to the documentation](http://docs.oracle.com/javase/tutorial/jdbc/basics/array.html), the Array type isn't supported so you need to insert the data a different way. – Thomas Apr 01 '13 at 13:43
  • I want to insert my string array(s1) into the database. – karthikbv Apr 01 '13 at 13:58
  • 1
    You can't, because mysql doesn't support Array types. This answer may help. http://stackoverflow.com/questions/12176709/how-can-i-simulate-an-array-variable-in-mysql – Thomas Apr 01 '13 at 14:00
  • Instead of using the setArray() method, what else can I do to insert the string array s1? – karthikbv Apr 01 '13 at 14:03
  • @karthikbv Maybe you should update your question with describing what you want to achieve and not the 'solution' you have in mind. MySQL doesn't support arrays, so storing arrays is not possible. – Mark Rotteveel Apr 01 '13 at 15:19
  • 1
    I thank everyone for all the help you have given. Since arrays cannot be stored directly in mysql, I have used the setString() method and for loop to store the string array values. – karthikbv Apr 02 '13 at 08:31