aspose file tools*
The moose likes HTML, CSS and JavaScript and the fly likes How to connect jdbc with javascript Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "How to connect jdbc with javascript" Watch "How to connect jdbc with javascript" New topic
Author

How to connect jdbc with javascript

Manikanta Mogalluri
Greenhorn

Joined: Dec 31, 2008
Posts: 11
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.


With warm regards, Manikanta Mogalluri
SCJP(90%), SCWCD(100%)
Devaka Cooray
ExamLab Creator
Saloon Keeper

Joined: Jul 29, 2008
Posts: 3053
    
  36

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.


Author of ExamLab ExamLab - a free SCJP / OCPJP exam simulator
What would SCJP exam questions look like? -- Home -- Twitter -- How to Ask a Question
Arnav Velimala
Ranch Hand

Joined: Jun 04, 2007
Posts: 37

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

Best Rgds,
Arnav.
Saifuddin Merchant
Ranch Hand

Joined: Feb 08, 2009
Posts: 605

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.


Cheers - Sam.
Twisters - The new age Java Quiz || My Blog
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61010
    
  65

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.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Saifuddin Merchant
Ranch Hand

Joined: Feb 08, 2009
Posts: 605

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

Joined: Jul 11, 2001
Posts: 15299
    
    6

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.


GenRocket - Experts at Building Test Data
Saifuddin Merchant
Ranch Hand

Joined: Feb 08, 2009
Posts: 605

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

Joined: Jul 11, 2001
Posts: 15299
    
    6

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

Joined: Jan 10, 2002
Posts: 61010
    
  65

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

Joined: Jun 04, 2007
Posts: 37
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

Joined: Feb 08, 2009
Posts: 605

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.
 
subject: How to connect jdbc with javascript