2

I would like a suggestion, then usually I load data on the database in this way:

PreparedStatement prep = con.prepareStatement ("INSERT INTO TABLE (NAME, LAST NAME) VALUES (?,?)");
             prep.setString (1, name);
             prep.setString (2, last name);
             prep.executeUpdate ();

I would like a way to avoid indicate a data reference index, that is, I would like to send data to the PreparedStatement untidily no index, I would like to send the data and then it will be the API to set the correct fields, it could use something like this (note that I reversed the surname with the name, sending the last name first, and the API should add it to the second field )

PreparedStatement prep = con.prepareStatement ("INSERT INTO TABLE (NAME, LAST NAME) VALUES (?,?)");
             prep.setString (surname, name);
             prep.setString (NAME, name);
             prep.executeUpdate ();
mustaccio
  • 18,234
  • 16
  • 48
  • 57
Frank Pentangeli
  • 336
  • 2
  • 6
  • 20

3 Answers3

1

The JDBC standard does not support named parameter markers in PreparedStatement, however, some vendor implementations of the JDBC driver do support them -- here's an example of the DB2 JDBC extension. Check documentation for your particular database vendor's driver implementation.

mustaccio
  • 18,234
  • 16
  • 48
  • 57
0

jdbc does not natively support named parameters in prepared statements. I found this answer that might answer your question.

Depending on the database you use (Oracle, MySQL, etc.) you may need slightly different tools.

Community
  • 1
  • 1
Cas
  • 758
  • 14
  • 36
0

Looking at the JAVA PreparedStatement documentation from ORACLE. There is no such methods.

The methods that are available looks generally like this:

set...(int parameterIndex, SomeObject variableName)

Young Emil
  • 2,220
  • 2
  • 26
  • 37