The repository consists of source code of Mulesoft internship program via NJC Labs. There is a Web page where a button named Create Table. By clicking the button, a table named 'movies'
is created in database. Then, user have to put details of the table by a form in the web page. And at the last, a table in the web page shows the chart of movies.
1. HTML Code
<form action="insertDataInTable.jsp" method="get" autocomplete="off">
<label for="movieName">Movie Name <span>*</span></label><br>
<input type="text" placeholder="Enter movies name" name="movieName" required=""><br><br>
<label for="actorName">Actor Name <span>*</span></label><br>
<input type="text" placeholder="Enter actor name" name="actorName" required=""><br><br>
...
</form>
2. JSTL Code
<sql:setDataSource var = "snapshot" driver = "com.mysql.cj.jdbc.Driver"
url = "jdbc:mysql:https://localhost:3306/dummydb"
user = "root" password = "admin"/>
<!-- check if table exists or not -->
<sql:query dataSource = "${snapshot}" var = "result">
SELECT COUNT(*) as t FROM information_schema.tables WHERE table_schema = 'njcLabDb' AND table_name = '<%= tableName%>';
</sql:query>
<c:forEach var = "row" items = "${result.rows}">
<c:choose>
<c:when test="${row.t == 1}">
<h2> <c:out value="y" /> </h2>
<% session.setAttribute("check", "Table name exists not need to create !!");%>
<c:redirect url = "index.jsp?tName=movies"/>
</c:when>
<c:otherwise>
...
</c:otherwise>
</c:choose>
</c:forEach>
3. JVAV Code
Class.forName(JDBC_DRIVER);
conn = DriverManager.getConnection(DB_URL, USER, PASS);
stmt = conn.createStatement();
String sql;
//select query for get data from database
sql = "select * from movies";
rs = stmt.executeQuery(sql);
boolean empty = true;
// show data to jsp
while (rs.next()) {
out.println("<tr><td>" + rs.getString("name") + "</td><td>" + rs.getString("actor") + "</td><td>" + rs.getString("actress") + "</td><td>" + rs.getString("director") + "</td> <td>" + rs.getString("yearOfRelease") + "</td></tr>");
empty = false;
}
if (empty) { // check empty or not, if empty then show no data found
out.println("<tr><td colspan =" + 5 + "> no data found !!</td></tr>");
}
id | name | actor | actress | director | yearOfRelease |
---|---|---|---|---|---|
1 | ghosh | sneha | paul | subham | 2020 |
... | ... | ... | ... | ... | ... |
Index Page
Movies List