Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 9 of 9

Thread: running script in Postgres via JDBC

  1. #1
    Junior Member
    Join Date
    Nov 2013
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question running script in Postgres via JDBC

    Hi,
    I have a spatial database in Postgres/PostGIS and SQL queries developed to manipulate the data. Now I want to build a GUI (user interface) with help of JAVA, JAI on NetBeans. I would like to know if there is a way to access and manipulate data in Postgres database using already developed SQL queries without having to code the queries in java. Simply call the query and run it in database via JDBC.

    Thanks
    Varu


  2. #2
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,320
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: running script in Postgres via JDBC

    By script, are you referring to a stored procedure? If so, see Using Stored Procedures (The Java™ Tutorials > JDBC(TM) Database Access > JDBC Basics) If not, then please elaborate.

  3. #3
    Junior Member
    Join Date
    Nov 2013
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Arrow Re: running script in Postgres via JDBC

    Quote Originally Posted by copeg View Post
    By script, are you referring to a stored procedure? If so, see Using Stored Procedures (The Java™ Tutorials > JDBC(TM) Database Access > JDBC Basics) If not, then please elaborate.
    Actually I am working on postgres database and as such i do not have stored procedures. I have stored .sql files which contain predefined functions provided in postgres/PostGIS. So I do not want to create SQL query in java. I want to access these .sql files and run them in postgres on a button click from GUI developed on java (using NetBeans).

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: running script in Postgres via JDBC

    Are you asking about writing a java program that will create a commandline:
    "command filename" to execute?
    The program(command) will execute in its own process.
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,320
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: running script in Postgres via JDBC

    Sounds to me like you can just read the .sql file and execute the commands within. Have you tried this?

  6. #6
    Junior Member
    Join Date
    Nov 2013
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: running script in Postgres via JDBC

    Hi copeg,
    Yes thts exactly what i wish to do, but dont know how to do, rather dont knw how to code tht in java. Kindly help.

    --- Update ---

    Quote Originally Posted by Norm View Post
    Are you asking about writing a java program that will create a commandline:
    "command filename" to execute?
    The program(command) will execute in its own process.
    ya something to tht effect, but not write the whole query in java. Instead use prebuilt queries stored in .sql files.

  7. #7
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: running script in Postgres via JDBC

    Can the .sql files be execute from the commandline:
    SomeCommand SomeFile.sql

    That commandline can be built and executed by a java program.
    If you don't understand my answer, don't ignore it, ask a question.

  8. #8
    Junior Member
    Join Date
    Nov 2013
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: running script in Postgres via JDBC

    "I have to develop a user friendly information tool that uses raster and vector database. For my SQLs developed using Postgres/Postgis I would like to have a GUI that would run them on a user click of button, rather than the user have to type whole SQL commands. How do I develop and link the GUI which would run the SQLs at the back end ? "

  9. #9
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: running script in Postgres via JDBC

    run the SQLs at the back end
    Have you worked out that part yet?
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Reg - inserting json data to postgres db.
    By ramya in forum JDBC & Databases
    Replies: 2
    Last Post: August 27th, 2012, 01:34 PM
  2. Reg - connecting java to postgres database
    By ramya in forum JDBC & Databases
    Replies: 2
    Last Post: August 27th, 2012, 12:50 PM
  3. [SOLVED] Making Binary Converter script from scratch, running into math issue.
    By mwebb in forum What's Wrong With My Code?
    Replies: 9
    Last Post: November 8th, 2011, 07:47 PM
  4. PRoblem Running Executable script in linux
    By ntu in forum File I/O & Other I/O Streams
    Replies: 0
    Last Post: May 2nd, 2011, 06:06 AM
  5. JDBC Script-Projet + Swing Interfaces
    By kawazaki123 in forum JDBC & Databases
    Replies: 0
    Last Post: July 5th, 2010, 01:25 PM