Results 1 to 2 of 2

Thread: Selecting schema with JdbcTemplate

  1. #1
    Join Date
    Dec 2010
    Posts
    26

    Default Selecting schema with JdbcTemplate

    Hi

    I am using PostgreSQL and i need to select schema dynamically for each query based on the user.

    Foe example, if user is abc, I have to run:
    set SEARCH_PATH to abc;
    select * from mytable;

    (assuming that every user has mytable in his/her schema)

    when i was using JDBC it was simple I used to create a connection and i was then able to run the 2 queries on the same connection.

    Now I have switched to Spring+JDBC and i'm using JdbcTemplate to run the queries as i found it simple and easy to use. But JdbcTemplate creates a new connection every time i execute a query using the execute() method. Is there any way i can run multiple queries in on the same connection.

    I think it will be better if i can select the schema at beginning of each transaction using @Transactional annotation

    Can anyone suggest how to do this?

    Thanks
    Amit Khanna

  2. #2
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,625

    Default

    For starters use proper tx management, that way you have the same connection for the whole transaction.
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •