最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

How to access an Access database using JavaScript? - Stack Overflow

programmeradmin1浏览0评论

I have to display marks of my students through my site. The database is created using Microsoft Access. How can I display the marks of each student in a table, as they enter the registration number?

I have to display marks of my students through my site. The database is created using Microsoft Access. How can I display the marks of each student in a table, as they enter the registration number?

Share Improve this question edited Apr 12, 2011 at 14:23 Peter Mortensen 31.6k22 gold badges110 silver badges133 bronze badges asked Dec 16, 2008 at 10:15 shameershameer 2
  • Possible duplicate of: Are there JavaScript bindings for MySQL?. – Peter Mortensen Commented Apr 12, 2011 at 14:36
  • the link from @PeterMortensen is incorrect and should be stackoverflow.com/questions/298057/… – kttii Commented Dec 13, 2019 at 15:07
Add a comment  | 

10 Answers 10

Reset to default 6

JavaScript can't directly access the database. You'll need to have some server-side component that takes requests (probably via HTTP), parses them and returns the requested data.

Then the JavaScript could access that component to fetch the data (hm ... smells like AJAX).

I know this is an old question, but I happened to come across this project, AccessDB, at the same time as this question so I figured I'd post it. Note that it says it is for use with Internet Explorer. I'm guessing they are using a Microsoft only feature to access the file, but I really haven't looked into it.

From their website:

ACCESSdb is a JavaScript library used to dynamically connect to and query locally available Microsoft Access database files within Internet Explorer. All you need is an .mdb file; Access does not even need to be installed!

http://accessdb.sourceforge.net/

Why do you want to use Javascript? It runs in the browser of the site's visitors, and even if there were a way to have it directly access a database (which there isn't), it would be a horrible security risk, since it would have to contain the DB password, so that each visitor of the site could get full access to the DB.

What you need is something that runs on the server and accesses the DB to deliver different pages to the visitor depending on data entered in an HTML form. Typical languages used for this are PHP, Perl, Ruby or ASP.

Also note that MS Access is a very poor choice as a DB backend to a web app since it does not support concurrent access from different users.

All in all it looks like you need more direct help than this site can provide; try finding a web app specialist in your area.

This question has been asked a long time ago, recently i found something helpful for future visitors. You can actually access your database via this javaScript library called mysqljs,which can be downloaded from http://www.mysqljs.com

Code synax:

          MySql.Execute(
    "mysql.yourhost.com", 
    "username", 
    "password", 
    "database", 
    "select * from Users", 
    function (data) {
        console.log(data)
});

Note: There is no security by default in this you are to code your own security

If you're looking for client-side database access, then what everyone else said.

If you're just looking for a way to access a database (NOT in a browser), and Javascript is the language you're most comfortable with, try JSDB. (It's a Javascript shell that has bindings for databases via ODBC, SQLite, and flat files) I've used it a lot and it's my preferred scripting shell.

I havent used M$ Access for a very long time, but I think they have some pretty good ways to export data to an HTML format. That will be static HTML code, but that could be enough for what you want to do. Definitely easier than writing a DB backend ...

JavaScript (or any client-side language) has no ability to access something which is still located on the server. You're best option is to use an AJAX implementation and have a series of web services which you can query from your JavaScript and return the results in a usable format (most likely JSON).

You are think from a client side, whereas you should be thinking on the server side.

You need a script on the server side that will query Access, and create the HTML for it, depending upon the value of a registration number supplied in a form.

The scripting language is up to you. Given that you are using Access, I imagine one of the Microsoft family of languages would be best, and that your institution will have a web server already (presumably IIS) to host your website.

First things first:

  • What server software is your institution running? This determines the best programming language to use.
  • What budget do you have. If it is near zero, then you are looking at free IDEs. It might be better to develop in Eclipse and deploy on Tomcat, regardless of the server OS.
  • What languages do you know?
  • Get a book on programming websites using your technology of choice. For example with Java I'd suggest using Struts and Tiles for a simple website like this.
  • You might want to migrate the data from Access to a database backend - MSSQL if your institution already has a license, or MySQL or PostgreSQL if you have a budget of zero.

From your question it sounds like this is all new to you. This is a small project however, so an ideal start to learning how to write interactive websites.

Here is a simple ASP (vbscript) script that will dump your data into a table. You can edit the path and query to suit your situation. As mentioned by others, it does not provide decent security.

Call it with FILENAME.asp?regno=xxxxx

<%
Set Conn = Server.CreateObject("ADODB.Connection")
Conn.Open "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=c:/YourDatabase.mdb"
SQL = "Select * from TABLENAME where regno=" & request("regno")
set RS= Conn.execute(SQL)
%>
<table>
    <tr>
    <% for x=0 to rs.fields.count-1 %>
        <th><%=RS.fields(x).value%></th>
    <% next %>
    </tr>
    <% do until RS.eof %>
        <tr>
            <% for x=0 to rs.fields.count-1 %>
                <td><%=RS.fields(x).value%></td>
            <% next %>
    </tr>
    <% rs.movenext %>
    <% loop %>
</table>
<%
RS.close()
set Conn=nothing
%>

You could use PHP to pass the login details to the access database so that you can provide a more secure login. Better still use mySql with PHP.

发布评论

评论列表(0)

  1. 暂无评论