• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to connect jdbc with javascript

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 7134
1360
IntelliJ IDE jQuery Eclipse IDE Postgres Database Tomcat Server Chrome Google App Engine
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 608
Firefox Browser Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 608
Firefox Browser Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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...


 
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 608
Firefox Browser Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 608
Firefox Browser Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic