I'm using Eclipse EE, Tomcat 6 server connected to MySQL server on win7. I was able to connect to a database through JSP and send commands like SELECT and DESCRIBE but if I try to create a table the JSP code will simply not run! Why is that? (Checked my SQL codes on the MySQL command line and it worked. )
JSP error:
org.apache.jasper.JasperException: An exception occurred processing JSP page /index.jsp at
JSP Coding:
try // DB login
{
String connectionURL = "jdbc:mysql://localhost/ofir";
Class.forName("com.mysql.jdbc.Driver").newInstance();
con = DriverManager.getConnection(connectionURL, "root", "");
stmt = con.createStatement();
connected = true;
}
catch(Exception ex)
{
out.println("Unable to connect to database.");
connected = false;
}
rs = stmt.executeQuery("CREATE table users (fname varchar(50), nname varchar(20), pass varchar(50), email varchar(50), gender boolean, age int(3), region varchar(10), notes varchar(1000))"); // Line of the error
*To be noted about the code- all variables are declared globally using ' <%! '
For CREATE TABLE, we have to use stmt.executeUpdate(sql)
. Not stmt.executeQuery(sql)
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments