Note that there are some explanatory texts on larger screens.

plurals
  1. POAccessing Database using JSP
    text
    copied!<p>I am learning JSP and I want to create a table in mysql using JSP. I have the following code. </p> <pre><code> &lt;%@ page contentType="text/html;charset=UTF-8" %&gt; &lt;%@ page errorPage="error.jsp" %&gt; &lt;%@ page import="java.sql.*" %&gt; &lt;html&gt; &lt;head&gt; &lt;title&gt;MySQL Database creation&lt;/title&gt; &lt;style&gt; { font-size: 12px; font-family: Verdana } &lt;/style&gt; &lt;/head&gt; &lt;body&gt; &lt;h2&gt;Creation of a books database&lt;/h2&gt; &lt;jsp:declaration&gt; Statement stmt; Connection con; String url = "jdbc:mysql://localhost:3306/"; &lt;/jsp:declaration&gt; &lt;jsp:scriptlet&gt;&lt;![CDATA[ Class.forName("com.mysql.jdbc.Driver"); con = DriverManager.getConnection(url, "root", ""); stmt = con.createStatement(); stmt.executeUpdate("CREATE DATABASE books"); con.close(); ]]&gt;&lt;/jsp:scriptlet&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>and my error.jsp page is</p> <pre><code> &lt;%@ page contentType="text/html" pageEncoding="UTF-8"%&gt; &lt;%@ page isErrorPage="true" %&gt; &lt;html&gt; &lt;head&gt; &lt;title&gt;Error page&lt;/title&gt; &lt;style&gt; { font-size: 12px; font-family: Verdana } &lt;/style&gt; &lt;/head&gt; &lt;body&gt; &lt;h2&gt;Error occured!&lt;/h2&gt; &lt;p&gt;Message &lt;jsp:expression&gt; exception.getMessage() &lt;/jsp:expression&gt; &lt;/p&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>When I run it, it is getting redirected to error page and getting the output as below:</p> <p>Error occured! Message com.mysql.jdbc.Driver </p> <p>Where am I going wrong?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload