Javascript - how to directly interact with db? - javascript

I have an excel sheet, a JS application and a db. excel sheet has data. I need to open the file and read data from the JS application and insert it into the db(say oracle db). How to?
I think we cannot open and close file in JS, pls correct me if i am wrong since it poses a security issue. If that is the case, say if we have updated the data in the grid, or table in the JS application. and we want to insert all the data in to the db, how do we do it?

First- there is pretty good module to read/write excel files in javascript-client or javascript-server:
js-xlsx
Someone has used it and provided a blog on its usage here
Second- You have to involve one more tier (server) to get the work done as per security standards. Or another option is BaaS (Back-end-as-Service) like Parse, Firebase to serve your client as database, it lets you directly save your stuff without involving/writing server. Or other option is to use SaaS like Mongolab, it exposes api for client to directly save into db.
Happy Helping!

You cannot do this safely. You need a webservice that the javascript app can call and that service would write to the database. So you should build a restful web api.

You need a Proxy Service for interacting to DB. There is no db-connectors for JS. The simplest way to achieve your goal is to choose one of the scripting languages which can run on your server. Such as PHP, Python, ASP.NET, ASP etc. I suggest PHP or Python.

Related

How to create a local database using JSON and JavaScript for webapp

I need to develop a simple webapp with a login system, users and data saved to each one of those users, with no knowlege of PHP or Data bases, only HTML, JavaScript/JQuery and JSON.
I must be able to sign up, log in and save some data (it's an online store, i must be able to save purchases historic, list of avourite products, user preferences, etc), all this locally only.
What is the best way to do this?
Security issues are not relevant.
I'm sorry for the bad english, I'm not a native speaker.
Hope you can help me!
You can use localstorage to use it as a db engine, but it is really limited,
You can use IndexedDB to use a localdb for you webapp.
Than will help you yo achieve your goals.
Remember that only moderm browser support IndexedDB, so you can check if your browser support it, else you can send a message for the user, to update the browser or fallback to localstorage
Since you are not using PHP, i would Recommend looking into using Node.js for the server-side part of your app. Node.js is written with javascript, so it will be relatively easy to learn.
On the website, you can use HTML forms to send data to the server using JSON. The other parts of your app can be built using HTML, CSS and javascript.
Although i recommend using SQL, there are other ways to store data like using MongoDB.

How can i connect JavaScript to a SQL server?

I work as an intern in a manufacturing company that designed a HTML web page run by JavaScript that is supposed to show real time statistics of the machine lines.
To do this it must connect to a SQL server in real time to obtain the data that it needs to display charts and reports.
I have good knowledge of other programming languages but I'm a rookie at JavaScript and I would like to know the safest way to do this, since the database contains sensitive data.
Can this be done?
You need some sort of middleman to connect to the database. Since you want to do this with JavaScript, I suggest you checkout NodeJS . You can then build a simple API that when consumed it will return the data required. One benefit of building an API is you will be able to consume it from the website that is already built without having to make any changes in the back end. You can simply use fetch the data from the front end using JavaScript.
Don't do this directly with Javascript in your HTML file in client-side(It is not secure).
Do this with any language that you know on the server side and read those data using ajax and display them in your HTML file.

Can i extract data from Oracle Database using JavaScript but without using ActiveXObject

I'm able to fetch data from Oracle database using ActiveXObject and JavaScript but I want to extract data from Oracle database and put data into an array without using ActiveXObject? Is it possible?
Javascript is a client-side language with heavy restrictions. It can't on it's own connect to the database without a service providing that functionality.
I would recommend writing a simple RESTful service layer to handle these requests. It doesn't matter what language you want to do it in, but if you like javascript you can use NodeJS.
I'd suggest avoiding ActiveXObject unless you want to write an IE specific application. Which makes me want to cry.

Database required for standalone application

I am constructing a standalone application that is comprised of HTML, CSS and JS files. The data that is being used by the application is being loaded from an XML file.
I, however, require the application to use a local database - something that would allow me to load, create and edit the data in this database using Javascript. Then package up the application and send it on (I am using webapp-xul-wrapper for this).
Could anybody give me some advice on how I could achieve this? The majority of solutions I have looked at use local storage or only keep the db table data for that particular session or require server side code.
To clarify, my application has a settings page that I would like to allow to edit my data and then keep that data persistent so that when the application is opened again the data is intact. Furthermore, if I was to send the application to someone else - that data would also be intact. Ideally my app would take its data from a physical file that could be passed around.
I hope this question makes sense!
Many thanks,
G.
I actually ended up using a packager called TideSDK (http://www.tidesdk.org/) which supports SQLLite out of the box and also seems to render my applications layout much clearer.
Many thanks!

Reading and writing to an external file using javascript?

I have an online storage account that I`m using for my homepage. Basically I have just made an "index.html" and stored there . and no php , asp is possible .
So If I must create a message form on the homepage and store the message in a separate text file in JSON format ,can it be done using javascript ?
also I need to query the Text file whenver I want to display the messages using javascript .
So far , I tried TaffyDB but realised it doesn`t have a way to persist the data after session closes. or maybe I missed something?
Thanks!
Short answer. No.
The JavaScript is client side. So it can do all sorts of cool stuff on the persons computer that visits your site but unless you're running some server side code that takes the JSON encoded data and does something with it then you're out of luck.
There are many alternatives.
If you don't want to run your own server side code then you could use a separate service like Parse.com that does REST and has a comprehensive API.
A mobile website can access Parse data from Javascript.
A webserver can show data from Parse on a website.
You can upload large amounts of data that will later be consumed in a mobile app.
You can download recent data to run your own custom analytics.
Applications written in any programming language can interact with data on Parse.
You can export all of your data if you no longer want to use Parse.
You can try with jQuery/AJAX. To read:
$.get("path_to_file", null, function(fileData) {
alert(fileData);
/* Your code goes here */
}, "text");
But in order to write, I think the only way is with some server-side language (PHP, ASP, etc)
The short answer is no.
You need to have some server-side support to persist the data on that server. You can, however, use client-side javascript to relay the information to a server that DOES support reading and writing of the data of course.
Technically, node.js is javascript that does support file reading and writing - but I assume that's out of the question for your environment :)
One crazy way (just as a thought experiment) to implement persistent storage for your web application without server side support is to have the clients talk to each other through P2P. This is possible with Flash or some java applet..etc. So as long as one client is up (perhaps your own comupter!), you'll have some form of persistent storage. Your server/webpage simply serves up this embedded object which does the actual work.

Categories

Resources