• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Bear Bibeault
  • Knute Snortum
  • Liutauras Vilda
Sheriffs:
  • Tim Cooke
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Ron McLeod
  • Ganesh Patekar
  • salvin francis
Bartenders:
  • Tim Holloway
  • Carey Brown
  • Stephan van Hulst

How do I insert List<String> together with other String attributes ?  RSS feed

 
Ranch Hand
Posts: 468
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have this method :



My question is how do I insert m.getSubjects() which will contains the values of List<String>subjects; into different rows.

Cos I can't create another ArrayList which will make m.getSubjects() giving me null values.

But, m.getSubjects will vary in size depending on the ParameterValues.

so, I have to loop over m.getSubjects and then use ps.setObject(2, m.getSubjects(i));

But, it doesn't get inserted into different rows!

I just can't figure out in the world how to make this part work.

I hope someone can tell me.

Tks.

 
Master Rancher
Posts: 920
17
Firefox Browser Hibernate IntelliJ IDE Java MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ABout what kind of rows are you talking? Of a db?
By the way you have a typo:
 
tangara goh
Ranch Hand
Posts: 468
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes. This forum is dedicated to JDBC and database so I thought rows would suffice. Sorry for my bad English.
The rows refers to the database.

And yes I left out a d in update. I hope you will overlook this mistake.

Tks.
 
Marshal
Posts: 67197
169
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

tangara goh wrote:Yes. This forum is dedicated to JDBC and database so I thought rows would suffice.


Actually, you had originally posted this in the Servlets forum. It was moved to the JDBC forum.
 
Sheriff
Posts: 23968
50
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

tangara goh wrote:But, it doesn't get inserted into different rows!



There could be a lot of reasons why that happens. But the code you posted doesn't let us guess which reason might be the real reason. And there's no point in attempting to list all of the possible reasons.

So here's what I would suggest. Write a small program which does nothing but create that list and then write it into several rows in your database. Use constant values to initialize the list and the other values. And then post the whole program and tell us what the result is when you run it. Make sure not to ignore error messages.

Okay?
 
Saloon Keeper
Posts: 2268
290
Android Angular Framework Eclipse IDE Java Linux MySQL Database Redhat TypeScript
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

tangara goh wrote:My question is how do I insert m.getSubjects() which will contains the values of List<String>subjects; into different rows.


Please post your tutor class so that we don't have to guess.
What does the DDL look like for your Tutors table?
Can you give an example of what you would want the rows would look for a given input?
 
Ron McLeod
Saloon Keeper
Posts: 2268
290
Android Angular Framework Eclipse IDE Java Linux MySQL Database Redhat TypeScript
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If I was doing something like this, I would separate Tutors and Subjects in to separate tables, and then have an associative/junction table to connect Tutors with Subjects.  Tutors and Subjects are only defined once in a single row in their corresponding table; with no unwanted redundant data.  The tutor_id and subject_id columns in the TutorSubjects table would be foreign-keys referencing the id columns in the corresponding Tutors and Subjects tables.

For example:
Add a new Subject to the school's offerings:

Add an additional Subject to a Tutor's repertoire:

Get Tutors' names and rates for a particular Subject (title of MATH-1 in this example):

Get Subject title and description for a particular Tutor (ID of 2 in this example):

 
Too many men are afraid of being fools - Henry Ford. Foolish tiny ad:
Programmatically Create PDF Using Free Spire.PDF with Java
https://coderanch.com/wiki/703735/Programmatically-Create-PDF-Free-Spire
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!