Skip to Main Content

Java Development Tools

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Problem with JDBC:MySql connection in JSP

460326Oct 26 2005 — edited Oct 31 2005
I am trying to connect MySql database called 'register' in the JSP login page of jDeveloper using the following code... But its not connecting and giving me different errors. I am using the driver called mysql-connector-java-3.1.11-bin.jar file, and I have put that file in to /jdev1012jdev/lib in windows. So can anyone help me out?

<%@ page language="java" contentType="text/html"
errorPage="errorpage.jsp" import="java.sql.*"%>

<html>
<head> <title>Login</title> </head>
<body>

<%
// 1. load the MySQL JDBC driver
Class.forName("org.gjt.mm.mysql.Driver");

// 2. open a connection to the "register" database


Connection Conn = DriverManager.getConnection("jdbc:mysql://localhost/register");


// 3. create a statement object for sending SQL queries
Statement Stmt = Conn.createStatement();

// 4. place query results in a ResultSet object
ResultSet RS =
Stmt.executeQuery("SELECT message FROM users WHERE name='" +
request.getParameter("name") + "' AND password=PASSWORD('" +
request.getParameter("password") + "')");

// 5. assign column 1 of the ResultSet to a String variable
String message = null;
while (RS.next()) { message = RS.getString(1); }

// 6. Clean up all ResultSet, Statement and Connection objects
RS.close();
Stmt.close();
Conn.close();
%>

<% if(message != null){ session.setAttribute("welcome", message); %>
<h3>Your login has succeeded. Thank you.</h3>
<% } else { %>
<h3>Your login has failed, please try again.</h3>
<% } %>

<a href="<%= response.encodeURL(db-login.jsp") %">">Continue...</a>

</body> </html></a>
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Nov 28 2005
Added on Oct 26 2005
6 comments
729 views