I am wanting to create an HTML form for entering/viewing data on localhost.
The data is in a file based H2 database on localhost.
Ideally, I'd like to use only client-side javascript and HTML so that the user does not need to run a local web server.
I have found some information here on how to connect: http://blog.jooq.org/2014/06/06/java-8-friday-javascript-goes-sql-with-nashorn-and-jooq/
but am wondering about the next step of how to integrate the connection/SQL queries into the web form.
I am aware that the use of javascript to connect to a database is usually frowned upon for security reasons, but for this use-case, it will only be accessing data on localhost.
Also, are there any recommended javascript libraries that would make this easier?
var someDatabaseFun = function() {
var Properties = Java.type("java.util.Properties");
var Driver = Java.type("org.h2.Driver"); //JDBC interface for H2
var driver = new Driver();
var properties = new Properties();
properties.setProperty("user", ""); // database username
properties.setProperty("password", ""); // database password
try {
var conn = driver.connect(
"jdbc:h2:~/db", properties); // connect to database
// Database code here
}
finally {
try {
if (conn) conn.close();
} catch (e) {}
}
}
someDatabaseFun();