how does it connect to the database

can anyone pls tell me how the below coding connect to the database, and if i want to change to use other type of connection, which part of the coding should i use? thank

loginAction.jsp

<%@ page contentType="text/html; charset=iso-8859-1" language="java" import="java.sql.*" errorPage="" %>

<html><!-- InstanceBegin template="/Templates/biome.dwt.jsp" codeOutsideHTMLIsLocked="false" -->

<head>

<!-- InstanceBeginEditable name="doctitle" -->

<title>Untitled Document</title>

<!-- InstanceEndEditable -->

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

<LINK href="bios.css" type=text/css rel=stylesheet>

<!-- InstanceBeginEditable name="head" --><!-- InstanceEndEditable -->

</head>

<body leftmargin="0" topmargin="0">

<%@ include file="useAndImport.jsp" %>

<%

String username = (String)session.getAttribute("username");

session.setMaxInactiveInterval(10*60);

boolean isLoggedIn=work.isUsable(username)?true:false;

%>

<table height="22" border="0" cellpadding="0" cellspacing="0" bgcolor="#CC3300" class="statusloginsearch">

<tr>

<SCRIPT LANGUAGE="JavaScript">

<!-- Idea by: Nic Wolfe (Nic@TimelapseProductions.com) -->

<!-- Web URL: http://fineline.xs.mw -->

<!-- This script and many more are available free online at -->

<!-- The JavaScript Source!! http://javascript.internet.com -->

<!-- Begin

function popUp(URL) {

day = new Date();

id = day.getTime();

eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=0,width=600,height=500');");

}

// End -->

</script>

<form action=loginAction.jsp method=POST>

<td width="77%" valign="baseline" nowrap id="statusbar"> <% if (isLoggedIn)

out.println("<img src=images/active.gif width=10 height=15 align=middle><font size=1 color=white face=Verdana, Arial, Helvetica, sans-serif><b>Welcome, " + username + " &nbsp;</b></font>");%> <% if (!isLoggedIn) { %>

<font color="#FFFFFF" size="1" face="Verdana, Arial, Helvetica, sans-serif">Username:</font><font size="1" face="Verdana, Arial, Helvetica, sans-serif">

<input type=text name=username class="form" ><%= work.getValueAttribute(username) %> >

<font color="#FFFFFF"> Password:</font>

<input type=password name=password class="form">

<input type="submit" name="action" value="Login" class="formbutton" onfocus="this.blur()" onmouseover="this.className='formbuttonover';" onmouseout="this.className='formbutton';" onmousedown="this.className='formbuttonover';" onmouseup="this.className='formbuttonover';">

<input type="reset" name="action" value="Reset" class="formbutton" onfocus="this.blur()" onmouseover="this.className='formbuttonover';" onmouseout="this.className='formbutton';" onmousedown="this.className='formbuttonover';" onmouseup="this.className='formbuttonover';">

<a href="javascript:popUp('membersAccess.jsp')"><img src="images/question.gif" alt="what's this?" width="15" height="15" border="0" align="middle"></a>

<% } %>

</font></td>

</form>

<td width="23%" valign="baseline" nowrap id="statusbar"> <div align="right">

<% if (isLoggedIn)

out.println("<form action=SignOut.jsp method=POST><input type=submit name=action value=Logout class=formbutton onfocus=this.blur() onmouseover=this.className='formbuttonover'; onmouseout=this.className='formbutton'; onmousedown=this.className='formbuttonover'; onmouseup=this.className='formbuttonover';></form>&nbsp;<a href=tour.jsp><img src=images/newtothissite.gif border=0 align=middle></a>");%>

</div></td>

</tr>

</table>

<table width="650" border="0" cellspacing="4" cellpadding="1">

<tr>

<td><!-- InstanceBeginEditable name="main" -->

<table width="580" border="0">

<tr>

<td><strong><font color="#CCCCCC" size="+2" face="Arial, Helvetica, sans-serif">ERROR</font></strong></td>

</tr>

</table>

<%-- loginAction.jsp --%>

<%

String username1 = request.getParameter("username");

String password=request.getParameter("password");

boolean isUsername=work.isUsable(username1);

boolean isPassword=work.isUsable(password);

String usernameQuoted=work.getSingleQuoted(username1);

String usernameParam = work.makeUrlParameter("username",username1);

ResultSet resultset;

if(isUsername && isPassword) {

resultset=db.executeQuery

("SELECT * FROM users WHERE USERNAME = " + usernameQuoted);

if (resultset.next() &&

resultset.getString("password").equals(password))

{

out.println("<font color=green>You are logged on.</font>");

session.setAttribute("username", username1);

String accessLevel = resultset.getString("access_level");

session.setAttribute("access", accessLevel);

if(accessLevel.equals("0"))

{

response.sendRedirect("Welcome.jsp");

}

else if(accessLevel.equals("3"))

{

response.sendRedirect("Admin.jsp");

}

%>

<%

} else {

out.print(work.tryAgain(

"<font size=2 color=red face=Verdana, Arial, Helvetica, sans-serif><b>Your username and/or password are incorrect.</b>",

"Login.jsp"+usernameParam));

}

} else {

out.print(work.tryAgain(

"<font size=2 color=red face=Verdana, Arial, Helvetica, sans-serif><b>Your login information is incomplete.",

"Login.jsp"+usernameParam));

}

%>

<!-- InstanceEndEditable -->

</td>

</tr>

</table>

</body>

<!-- InstanceEnd --></html>

useAndImport.jsp

<%-- thingsToUseAndImport.jsp --%>

<jsp:useBean id="db"

class="kw.search.DbAccess"

scope="application"/>

<jsp:useBean id="work"

class="kw.search.Worker"

scope="application"/>

<jsp:useBean id="dataB"

class="bb.messageBoard.DataB"

scope="application"/>

<jsp:useBean id="forum"

class="bb.messageBoard.Forum"

scope="application"/>

<%@ page import="java.text.DateFormat, java.util.Vector, java.io.*" %>

DbAccess.java

package kw.search;

import java.sql.*;

public class DbAccess implements java.io.Serializable {

private Connection connection;

private Statement statement;

String db = "btc";

String user = "javauser";

String password = "javauser";

String dbUrl = "jdbc:mysql://localhost:3306/" +db;

//dbUrl = "jdbc:mysql://localhost:3306/"+db;

public DbAccess ()

throws ClassNotFoundException, SQLException

{

Class.forName("com.mysql.jdbc.Driver");

//connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/btc?"+"user=javauser&password=javauser");

connection = DriverManager.getConnection

(dbUrl+"?user="+user+"&password="+password);

connection.setAutoCommit(false);

statement = connection.createStatement();

}

public void executeUpdate(String sqlCommand)

throws SQLException

{

statement.executeUpdate(sqlCommand);

}

public ResultSet executeQuery(String sqlCommand)

throws SQLException

{

return statement.executeQuery(sqlCommand);

}

public void commit() throws SQLException

{

connection.commit();

}

public void rollback() throws SQLException

{

connection.rollback();

}

protected void finalize() throws SQLException

{

statement.close();

connection.close();

}

}

[8460 byte] By [pUnKzT3ra] at [2007-10-2 20:46:31]
# 1
This is the original post, but the thread is continued in a duplicate.
morgalra at 2007-7-13 23:30:22 > top of Java-index,Desktop,Developing for the Desktop...
# 2
do not post to this one.
morgalra at 2007-7-13 23:30:22 > top of Java-index,Desktop,Developing for the Desktop...