This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin in Action and have Dmitry Jemerov & Svetlana Isakova on-line!
See this thread for details.
Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

How can i connect to remote database server using swings  RSS feed

satyam vizag narayana
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

I am using a swing application.I am not using the Japplets.In this application i want connect to the remote database and store and retrieve the data in and from remote database.I want to access my remote database through the internet.

for that which thechnology i will use? wheather igo for

1. normal jdbc connections?
2. Using Rmi
3. using servlets if possible
4. r there any other technology

please suggest me which one is better and feasible. please give code to do that or any resources or links for the information.

Thanks in advance
Nathan Pruett
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1.) Normal JDBC should work OK (Just specify the correct URL for the connection, make sure you have the driver, make sure the network is open to the server, etc.) but will probably be a much more "fragile" solution than other options - since you are accessing the DB directly, any DB changes require a client change - whereas with other methods, you would be able to seperate client and server better.

2.) RMI could work too - you could hide the JDBC (or other data access) behind an RMI facade that would simply provide remote or serialized object versions of the data. Better than direct JDBC (because you are dealing with objects rather than directly with the database), and would certainly be sufficient, but there may be additional needs you have that might already be provided by another choice.

3.) Servlets are probably not the best choice - primarily because the dangers of SQL injection - using servlets and SQL, the first thing anyone thinks of is "Let's just make a servlet that takes a SQL string and calls the database". Very simple, but also very dangerous - because anyone can send any kind of SQL statement into this - deleting data, getting access to records they shouldn't, etc. Yes, it is possible to filter the input, but you have to be very careful, and it's easy to miss possible "bad" statements that can be sent - so it's better to just not use this.

4.) Other possible choices -
a.) Web Service - kind of like the servlet option, but more "object-like" - make sure you aren't sending SQL directly again - deal with objects - not SQL.
b.) EJB - may be more than you need - and probably a steep learning curve - but it should provide everything you should ever need for this plus more - transactions, objects instead of SQL, remote access, etc.
c.) Hibernate - or some other ORM (Object Relational Mapping) solution - point it at a database, tell it what tables to model as what kind of objects, and it handles the rest.

None of these are "the best" answer - it all depends on your exact project, the way your project accesses data, and your level of understanding of how to use any of these.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!