agora inbox for pgsql-sql@postgresql.org
help / color / mirror / Atom feedWould like to know what is the problem in my sql statement
4+ messages / 3 participants
[nested] [flat]
* Would like to know what is the problem in my sql statement
@ 2019-07-12 02:04 Karen Goh <karenworld@yahoo.com>
0 siblings, 2 replies; 4+ messages in thread
From: Karen Goh @ 2019-07-12 02:04 UTC (permalink / raw)
To: pgsql-sql@lists.postgresql.org
Hi,
I hope that I am in the right forum because I am using pgAdmin4 running on Windows 10 to manage my database.
However, the question I have is to do with a sql that is not working out quite right hence this forum.
The error I am getting is
org.postgresql.util.PSQLException: No value specified for parameter 1.
at org.postgresql.core.v3.SimpleParameterList.checkAllParametersSet(SimpleParameterList.java:257)
at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:290)
at org.postgresql.jdbc.PgStatement.executeInternal(PgStatement.java:441)
at org.postgresql.jdbc.PgStatement.execute(PgStatement.java:365)
at org.postgresql.jdbc.PgPreparedStatement.executeWithFlags(PgPreparedStatement.java:155)
at org.postgresql.jdbc.PgPreparedStatement.executeQuery(PgPreparedStatement.java:118)
at Controller.searchController.processRequest(searchController.java:123)
at Controller.searchController.doGet(searchController.java:77)
Basically, I am trying to retrieve from a table which contains the id and also the subjects as per the user input parameterValues.
Here's my code snippet.
Please tell me why it says no value specified for parameter 1.
HashMap<Integer, ArrayList<String>> tutorSubject = new HashMap<Integer, ArrayList<String>>();
String sql1 = "select tutor_id, subject_name from tutor_subject where subject_name in ("
+ builder.deleteCharAt( builder.length() -1 ).toString() + ")";
PreparedStatement ps2 = connection.prepareStatement(sql1);
rs = ps2.executeQuery();
if (rs.next()) {
while(rs.next()) {
// System.out.println("tutor ID=" + rs.getInt("tutor_id") + ", subjectName=" + rs.getString("subject_name"));
for( Object o : subjs ) {
int tutor_id = rs.getInt(1);
ps2.setInt(1, tutor_id);
int index = 1;
for( Object o : subjs ) {
ps2.setObject(index++, o );
for (int j = 0; j < tutorSubject.put(tutor_id, (ArrayList<String>) o).size(); j++) {
tutorSubject.put(tutor_id, (ArrayList<String>) o);
}
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: Would like to know what is the problem in my sql statement
@ 2019-07-12 02:11 Juan C. Olivares <juancri@juancri.com>
parent: Karen Goh <karenworld@yahoo.com>
1 sibling, 0 replies; 4+ messages in thread
From: Juan C. Olivares @ 2019-07-12 02:11 UTC (permalink / raw)
To: Karen Goh <karenworld@yahoo.com>; +Cc: pgsql-sql@lists.postgresql.org
Karen:
Can you just print sql1 to see which SQL statement are you executing?
On Thu, Jul 11, 2019 at 7:04 PM Karen Goh <karenworld@yahoo.com> wrote:
> Hi,
>
> I hope that I am in the right forum because I am using pgAdmin4 running on
> Windows 10 to manage my database.
> However, the question I have is to do with a sql that is not working out
> quite right hence this forum.
>
>
> The error I am getting is
> org.postgresql.util.PSQLException: No value specified for parameter 1.
> at
> org.postgresql.core.v3.SimpleParameterList.checkAllParametersSet(SimpleParameterList.java:257)
> at
> org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:290)
> at
> org.postgresql.jdbc.PgStatement.executeInternal(PgStatement.java:441)
> at org.postgresql.jdbc.PgStatement.execute(PgStatement.java:365)
> at
> org.postgresql.jdbc.PgPreparedStatement.executeWithFlags(PgPreparedStatement.java:155)
> at
> org.postgresql.jdbc.PgPreparedStatement.executeQuery(PgPreparedStatement.java:118)
> at
> Controller.searchController.processRequest(searchController.java:123)
> at Controller.searchController.doGet(searchController.java:77)
>
> Basically, I am trying to retrieve from a table which contains the id and
> also the subjects as per the user input parameterValues.
>
> Here's my code snippet.
>
> Please tell me why it says no value specified for parameter 1.
>
> HashMap<Integer, ArrayList<String>> tutorSubject = new HashMap<Integer,
> ArrayList<String>>();
>
> String sql1 = "select tutor_id, subject_name from tutor_subject where
> subject_name in ("
> +
> builder.deleteCharAt( builder.length() -1 ).toString() + ")";
>
>
> PreparedStatement ps2 =
> connection.prepareStatement(sql1);
>
> rs = ps2.executeQuery();
>
> if (rs.next()) {
> while(rs.next()) {
> // System.out.println("tutor ID=" +
> rs.getInt("tutor_id") + ", subjectName=" + rs.getString("subject_name"));
> for( Object o : subjs ) {
> int tutor_id = rs.getInt(1);
> ps2.setInt(1, tutor_id);
> int index = 1;
>
>
> for( Object o : subjs ) {
> ps2.setObject(index++, o );
> for (int j = 0; j <
> tutorSubject.put(tutor_id, (ArrayList<String>) o).size(); j++) {
>
> tutorSubject.put(tutor_id,
> (ArrayList<String>) o);
> }
>
>
>
--
Atte,
Juan Cristóbal Olivares
^ permalink raw reply [nested|flat] 4+ messages in thread
* Would like to know what is the problem in my sql statement
@ 2019-07-12 02:34 David G. Johnston <david.g.johnston@gmail.com>
parent: Karen Goh <karenworld@yahoo.com>
1 sibling, 1 reply; 4+ messages in thread
From: David G. Johnston @ 2019-07-12 02:34 UTC (permalink / raw)
To: Karen Goh <karenworld@yahoo.com>; +Cc: pgsql-sql@lists.postgresql.org <pgsql-sql@lists.postgresql.org>
On Thursday, July 11, 2019, Karen Goh <karenworld@yahoo.com> wrote:
>
>
> Please tell me why it says no value specified for parameter 1.
>
> HashMap<Integer, ArrayList<String>> tutorSubject = new HashMap<Integer,
> ArrayList<String>>();
>
> String sql1 = "select tutor_id, subject_name from tutor_subject where
> subject_name in ("
> +
> builder.deleteCharAt( builder.length() -1 ).toString() + ")";
>
>
>
Because you don’t have any parameter placeholder symbols in your query?
I.e., the question mark “?” character...
David J.
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: Would like to know what is the problem in my sql statement
@ 2019-07-12 12:22 Karen Goh <karenworld@yahoo.com>
parent: David G. Johnston <david.g.johnston@gmail.com>
0 siblings, 0 replies; 4+ messages in thread
From: Karen Goh @ 2019-07-12 12:22 UTC (permalink / raw)
To: David G. Johnston <david.g.johnston@gmail.com>; +Cc: pgsql-sql@lists.postgresql.org
Thank you all for telling me where is the problem. I was overwhelmed at attempting this for the first time and my eyes painful.
Now, it is working ok.
Thank you all for your help. Really appreciate it. On Friday, July 12, 2019, 10:34:37 AM GMT+8, David G. Johnston <david.g.johnston@gmail.com> wrote:
On Thursday, July 11, 2019, Karen Goh <karenworld@yahoo.com> wrote:
Please tell me why it says no value specified for parameter 1.
HashMap<Integer, ArrayList<String>> tutorSubject = new HashMap<Integer, ArrayList<String>>();
String sql1 = "select tutor_id, subject_name from tutor_subject where subject_name in ("
+ builder.deleteCharAt( builder.length() -1 ).toString() + ")";
Because you don’t have any parameter placeholder symbols in your query? I.e., the question mark “?” character...
David J.
^ permalink raw reply [nested|flat] 4+ messages in thread
end of thread, other threads:[~2019-07-12 12:22 UTC | newest]
Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2019-07-12 02:04 Would like to know what is the problem in my sql statement Karen Goh <karenworld@yahoo.com>
2019-07-12 02:11 ` Juan C. Olivares <juancri@juancri.com>
2019-07-12 02:34 ` David G. Johnston <david.g.johnston@gmail.com>
2019-07-12 12:22 ` Karen Goh <karenworld@yahoo.com>
This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox