As before we begin by creating a statement for sending SQL code to the database. Then we can 'execute' the given SQL statement to 'insert into' the existing students Table the values provided.
var student = stmt.execute('INSERT INTO students'4 values have been provided to match the 4 columns contained within the students Table:
+ " VALUES ('456789', 'Donald', 'Duck', '9');"
);
- StudentNo - 456789
- FirstName - Donald
- LastName - Duck
- Shoesize - 9
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Database Credentials | |
var dbAddress = ''; | |
var dbUser = ''; | |
var dbPassword = ''; | |
var dbName = ''; | |
// connect to SQL database | |
var db = Jdbc.getConnection('jdbc:mysql://' + dbAddress + ':3306/' + dbName, dbUser, dbPassword); | |
function insertStudent() { | |
// create a statement to perform a task | |
var stmt = db.createStatement(); | |
// insert a new student into existing students table | |
var student = stmt.execute('INSERT INTO students' | |
+ " VALUES ('456789', 'Donald', 'Duck', '9');" | |
); | |
// close connections after access | |
stmt.close(); | |
db.close(); | |
} |
No comments:
Post a Comment