Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Using a java program as a command line...

 
Keyser Logue
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello, I have written a program that will access a postgres database using jdbc.

It has a default query of Select * From Members, so that when it runs it will select everything from the members table and display it in the java screen that appears

My problem is, I then want this to work with a MYSQL database as well. Will I need to install a different JDBC or is there something I can change in the code

Basically, it is to produce one java program that can query both postgres and mysql, does anyone have any tips and/or help
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64713
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You just need to load the approriate driver, and make sure that the SQL syntax you use is common to both databases.
 
Keyser Logue
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Excellent, thankyou...

The only other point is, once I have typed in the command (for example Select * From FirstNames) I want to have a submit button which will process that command.

How do I set it so that the query is passed to the database, and also is there a way of setting it so that if it is an invalid query, an error message is returned?
 
Rachil Chandran
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
u could catch possible SQLExceptions that are thrown when your query is passed and display some message. Hope i got ur questions right
 
Keyser Logue
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the replies, one last thing:

The main thing I want is a log in screen, you know something like this:


Driver name (may use a drop down for this)

Database URL: (Text field??)

Username

Password

Once they are filled in, I want it to somehow process it when I press a submit button. How should I do that
 
Jason Moors
Ranch Hand
Posts: 188
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not really database specific, but you could pass the information as command line parameters or provide a simple Dialog window using Swing.

Check out the Swing Tutorial, which should give you and idea of what you want to do. In particular look at JFrame and JDialog.

Swing Tutorial

Dialog Window Tutorial

regards

Jason
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic