简体   繁体   中英

mySQL connection with javascript

Good day! Here's the situation. We are trying to connect our mySQL database using javascript. We already have the java codes to access the database, but the thing is, they are java files and I cannot find ways how to transform them to javascripts. How can these different classes (eg DatabaseClass.java, DBConnectionFactory.java, DBConnectionFactoryImpl.java) work together in an HTML file? Can someone provide a link which could help us with this?

PS We're just beginners. I hope you guys can understand what we are trying to do. Cheers!

You're mistaking that Java and Javascript are somehow related. They're not, and you can't just magically use Java classes in Javascript.

You need to have Java access the database, and communicate with the Java backend from Javascript.

You need to make a server call to get data from the database. It is bad practice to call the database directly from the client side (you don't want to expose a database login to the client).

If you know what to look for when the page is called you can make the page a servlet , JSP , CGI-script or any other technology that facilitates dynamic web pages.

If you know (or want to learn) java I would recommend a servlet (with java code) that forwards to a jsp (for the presentation). Note that you need an application server that supports servlets and jsp.

If you need to make the database call on the fly, after the page has loaded, you can use Ajax or AJAJ to call a servlet (or other server side facility).

my two cents: if you need to work with Java and a DB, don't go for HTML. HTML is static, while it seems you want a dynamic application. then the best option (for beginners) would be to learn basic JSP and Servlets.

it is possible to access a database using JavaScript (though I wouldn't recommend it), here and here you can find topics on that subject.

我认为您最好学习基本的JSP / servlet,然后再通过tomcat之类的Web服务器使用它...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM