Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to connect jdbc with javascript

 
Manikanta Mogalluri
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear All,

I got an assignment like connecting jdbc using javascript.

Previously i have connected jdbc using jsp however i want to know how to connect jdbc using javascript.

Kindly let me know if any issues.

With Warm Regards,
Manikanta Mogalluri.
 
Devaka Cooray
ExamLab Creator
Marshal
Pie
Posts: 4262
229
Chrome Eclipse IDE Google App Engine IntelliJ IDE jQuery Postgres Database Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't know is there a way to directly connect with a database from a JavaScript code. Because JavaScript runs on the client's side, and thus it is not good at all to establish such a connection from JavaScript.
 
Arnav Velimala
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Write the JDBC code in JSP. And make an AJAX call to that JSP from your javascript.

Best Rgds,
Arnav.
 
Saifuddin Merchant
Ranch Hand
Posts: 607
Firefox Browser Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nopes. You cannot do that. JavaScript cannot connect to a database using any method.
Probably the closest you can get is by using Ajax and connecting to the database via the normal fashion in Servet or JSP.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64631
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Arnav Velimala wrote:
Write the JDBC code in JSP. And make an AJAX call to that JSP from your javascript.

This is possibly the worst advice I have ever seen posted.

JDBC code has NO place in a JSP. Be sure to follow best practices and not pollute your JSPs with Java code -- especially database code.

The best way to satisfy your requirement is to use Ajax to access properly structured Java compoenents.
 
Saifuddin Merchant
Ranch Hand
Posts: 607
Firefox Browser Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:
Arnav Velimala wrote:
Write the JDBC code in JSP. And make an AJAX call to that JSP from your javascript.

This is possibly the worst advice I have ever seen posted.

JDBC code has NO place in a JSP. Be sure to follow best practices and not pollute your JSPs with Java code -- especially database code.

The best way to satisfy your requirement is to use Ajax to access properly structured Java compoenents.


I would assume that Arnav meant using the proper archtecture to connect to the database - and that you would need to use Ajax & Server Side components (JSP included) to connect to the database. Of course - I agree being explicit would have helped...


 
Gregg Bolinger
GenRocket Founder
Ranch Hand
Posts: 15302
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sam Mercs wrote:
Bear Bibeault wrote:
Arnav Velimala wrote:
Write the JDBC code in JSP. And make an AJAX call to that JSP from your javascript.

This is possibly the worst advice I have ever seen posted.

JDBC code has NO place in a JSP. Be sure to follow best practices and not pollute your JSPs with Java code -- especially database code.

The best way to satisfy your requirement is to use Ajax to access properly structured Java compoenents.


I would assume that Arnav meant using the proper archtecture to connect to the database - and that you would need to use Ajax & Server Side components (JSP included) to connect to the database. Of course - I agree being explicit would have helped...




Um, how did Arnav mean proper architecture when he specifically stated "Write the JDBC code in JSP" ? It's nice of you to defend him though.
 
Saifuddin Merchant
Ranch Hand
Posts: 607
Firefox Browser Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Gregg Bolinger wrote:
Sam Mercs wrote:
Bear Bibeault wrote:
Arnav Velimala wrote:
Write the JDBC code in JSP. And make an AJAX call to that JSP from your javascript.

This is possibly the worst advice I have ever seen posted.

JDBC code has NO place in a JSP. Be sure to follow best practices and not pollute your JSPs with Java code -- especially database code.

The best way to satisfy your requirement is to use Ajax to access properly structured Java compoenents.


I would assume that Arnav meant using the proper archtecture to connect to the database - and that you would need to use Ajax & Server Side components (JSP included) to connect to the database. Of course - I agree being explicit would have helped...




Um, how did Arnav mean proper architecture when he specifically stated "Write the JDBC code in JSP" ? It's nice of you to defend him though.


I am not sure what he meant. I would have meant poper architecture if I wrote JSP.
Frankly sometimes I think its ok to connect JDBC from a JSP specially for really small projects - you know demo kind or where you are just learning something else like Ajax. I guess thats just me though - i dont recommend it
 
Gregg Bolinger
GenRocket Founder
Ranch Hand
Posts: 15302
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The problem with that, Sam, is that from my experience those "example applications" often times wind up in production code. It's a whole lot better to just do it right from the get go. It requires much less work later on.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64631
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Gregg Bolinger wrote:The problem with that, Sam, is that from my experience those "example applications" often times wind up in production code. It's a whole lot better to just do it right from the get go. It requires much less work later on.

Quoted for truth.

Also, "Write the JDBC code in JSP" will be interpreted just that way by any novice, no matter how it was intended.
 
Arnav Velimala
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok. My mistake. My English needs improvement.

No Problem.

Here's what i meant:

Write a DAO(Data Access Object) that fetches the required data from your database. Call the DAO from JSP.
And make an AJAX call to that JSP from your javascript.

A less worst adivce or even worse?

Actually, i was trying to stress on AJAX - Calling a JSP from a JavaScript. Not on how to get data from DB in JSP.

ciao
 
Saifuddin Merchant
Ranch Hand
Posts: 607
Firefox Browser Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Gregg Bolinger wrote:The problem with that, Sam, is that from my experience those "example applications" often times wind up in production code. It's a whole lot better to just do it right from the get go. It requires much less work later on.


Agree Sherrif
Thats why I hardly do it - just when I'm learning something new or giving someobe else a quick exampe. I also make sure I delete all such code off - But I whole heartedly agree with what you say.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic