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 width="100%" height="22" border="0" cellpadding="0" cellspacing="0" bgcolor="#CC3300" class="statusloginsearch">
<tr>
          <SCRIPT LANGUAGE="JavaScript">
<!-- Idea by: Nic Wolfe ([email protected]) -->
<!-- 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 + "  </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';">
<img src="images/question.gif" alt="what's this?" width="15" height="15" border="0" align="middle">
<% } %>
</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> <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();
}

This section of your code makes the connection:
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();
}

Similar Messages

  • How can I connect to the database using ODBC within excel.

    Hi,
    How can I connect to the database using ODBC within excel and just refresh the data when needed.
    Thanks,
    Priyanka
    Edited by: user554934 on Jun 9, 2009 2:53 AM

    This is NOT an APEX relevant question, try posting it in the SQL/PL/SQL Forum..
    Thank you,
    Tony Miller
    Webster, TX

  • Sorry if tis is naive.  I have just bought my first iPad Retina Display.  I have WiFi at home but it has taken ages for me to connect as I needed all sorts of codes, passwords, detauils etc.   How does one connect to the web (Google) when one is out and a

    Sorry if this is a bit naive.  I have just bought my first iPad (Retina Display).  I have WiFi at home but it has taken me ages to get on-line as I needed all sorts of codes, passwords, numbers etc.
    How does one connect to the web (Google) when one is out and about?
    Thanks

    haha, You're welcome
    Maybe these links will be useful
    ipad manual/user guide
    http://manuals.info.apple.com/en_US/ipad_user_guide.pdf
    ipad support page
    http://www.apple.com/support/ipad/
    ipad assistant
    http://www.apple.com/support/ipad/assistant/

  • How does Imac connect to the internet?

    How does Imac connects to the internet?

    Through your ISP (internet service provider); once you set up an account with them, you can decide to connect via ethernet cable to their modem, or, if you have a router (which is connected to their modem, you can connect wirelessly.
    Is that what you were wondering about or did I misunderstand your question?

  • How can I connect to the database using the Oracle Remote Diagnostic Agent?

    Now I try to study RDA on Windows XP platform,when I run 'rda.cmd',there is a question 'Enter password for 'SYSTEM@'',what is the answer?
    Because I didn't know how to connect to database,there are many error messages - RDA-00510: SQL execution disabled,What can I do?

    Metalink Note:314422.1 to start
    It is asking you to tell how to connect to 'the database that you are investigating' over a network. The answer .... the password for the userid called 'system' in the database specified after the @
    I am confused ... you do not know how to connect to your database?

  • URGENT!!!!!!!! Tomcat 5.0 does not connect to the database !!!!!!

    We had an already existing system on tomcat 4.1.18. Since migrating to Tomcat 5.0, we are facing lots of problem while trying to connect to the database. The database in SQL Server 2000.
    The first time i try to connect (after restarting tomcat service) the system is able to connect to the database but after sometime it again stops connecting.
    The beans on our system are able to connect to the database without any problem but when we try using the same via http, it doesnt connect. The classpath is set properly. Also the database drivers are also the latest ones and in the proper place. We have placed them in the common/lib folder. We have checked that normal jsp pages which are not connecting to the database are working fine.
    Please HELP!!!!!!!!!!!
    Thanks in advance

    well.....Tomcat is not a database connecting engines.....U would need to check your db connection codes to check if you have missed anything.....so the first question will be
    1. How do u connect to the DB
    2. Which type of JDBC drivers are u using.
    Finaly, tomcat is not at fault...its the fault of you configuration
    Cheers,
    Manjun ath

  • How does one find out the database name , service name in a database

    hi,
    how do u find out the database name , service name , SID in a database.
    Please reply.
    Thanks ,
    Regards,
    RC

    This particular information is available in the view V_$PARAMETER owned by SYS. But you can also login with Server Manager as user INTERNAL and run:
    SHOW PARAMETERS
    The entries pertaining to the naming of the database are:
    1. db_name
    2. db_domain
    3. db_name
    4. instance_name
    5. service_names
    GLOBAL_NAME is a static (not changing) Data Dictionary view which has just 1 attribute (column) called GLOBAL_NAME.
    When you run:
    select GLOBAL_NAME from GLOBAL_NAME;
    You are returned the full global name of the database, i.e. the db_name and the db_domain joined together by dot (.) For e.g. if your db_name = mgmt and db_domain = tech.co.in, then your global_name will be MGMT.TECH.CO.IN.
    Ciao.
    null

  • How does WebMail connect to the Mail Store

    Some WebMail products have HTTP connect directly to the Mail Store Database. Other products have HTTP connect to IMAP and let IMAP connect to the Mail Store database.
    How does iMS5 do it?

    Hi,
    iMS use separated daemon(mshttpd).
    It is composited httpd daemon + message access daemon.
    It is not normal http daemon.(mshttpd can use only
    iPlanet Messaging Server)
    When user connect the server using iMS 5 Webmail
    (It is named Messenger Express), the mshttpd recevied
    that requst and communicate with stord(mail box daemon)
    and fetch the mail, and make new html page.
    user -> mshttpd -> stored -> server mailbox
    Other Webmail use IMAP or POP Protocal(standard protocal) for communicate
    with messaging server, but mshttpd use itself protocal.
    (It is not standard)
    But, you can use imap of pop protocal for making new
    webmail server.
    Regards

  • How can I connect to the portal homepage on a 9i Database

    I successfully installed Oracle 9iAS on a MS Windows NT machine
    and configured the Portal Server on an Oracle 9i Database on
    another machine (Windows 2000).
    But when I try to call the portal homepage (portal30.home), I
    get the following error: "The preference path does not exist:
    Oracle.Portal.Page (WWC-51000)".
    I can successfully call the .../admin_/gateway.htm page and
    connect over there to the database.
    The shared_pool_size parameter is large enough (92274688).
    I installed the portal server manually, without the GUI, because
    the connection to the database during the installation was only
    enabled as SYSDBA or SYSOPER.
    How can I also get connected to portal homepage?
    Thanks,
    Reinaldo

    can i connect my roku box to the 2nd AE's ethernet port?
    Yes
    will it make any difference? (as opposed to the roku box, used for netflix, picking up it's signal wirelessly).
    Probably not, since the AirPort Express is picking up its signal via wireless.
    The same signal just appears at the Ethernet port. If anything, the signal at the Ethernet port will have a bit less bandwidth than the wireless signal since the Express must convert from wireless to Ethernet...and you always lose something in the conversion process.
    Normally, you would use the Ethernet port if a device did not have wireless capability.

  • How do i fix my wifi if it connects and the bars are blue but no check sign appears next to the wifi name and does not connect to the internet???

    How do i fix my wifi if it connects and the bars are blue but no check sign appears next to the wifi name and does not connect to the internet???

    Did you already try to reset the iPod by holding the sleep and home button for about 10sec, until the Apple logo comes back again? You will not lose data.
    If this does not work, try to reset the network settings in Settings/General/Reset. After that you'll have to put in the passwords for all known networks again.
    More troubleshooting can be found here:
    iOS: Troubleshooting Wi-Fi networks and connections

  • How is the best way to connect to the Database ?

    I just have a question regarding to the connection to the Oracle DB.
    Every time I create a new JSP I am writing java code such as:
    Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();
    conn = DriverManager.getConnection("jdbc:oracle:thin:@host:1521:DB",
    "user",
    "pwd");
    Is there a way I can reuse the connection that we create on JDeveloper on the tab Connections, under the Database node ?
    Because I would like to centralized more the way how I connect to DB.
    Thanks!
    Giovani

    That is a nice solution, but only works if you use embedded OC4J, if not you must define datasources, maybe in standalone OC4J, OAS, JBoss, etc
    this is because the embedded OC4J automatically create datasources if it sees database connectiones created through Connections Tab

  • I have a new time capsule (replace my old time capsule).  I want to erase my old one.  My computer does not see the old one anymore, how do I connect it (the old TC is not connected to modem)

    I have a new time capsule (replace my old time capsule).  I want to erase my old one.  My computer does not see the old one anymore, how do I connect it (the old TC is not connected to modem).  I want to erase it and then use it as either a second hard drive (sired/sirelesly?) or as a hard drive/bridge.  So,
    1.  why doesn't my cmputer see the old TC
    2  once i have solved that, how do I erase the old one
    3.  Can I use the old one as a supplemental hard drive
         a.  wired?
         b. wirelessly?
    4.  Can I use the old one as a range extender?
    I know .. a lot of questions but I would appreciate any help.
    Thanks

    sgetraer wrote:
    I have a new time capsule (replace my old time capsule).  I want to erase my old one.  My computer does not see the old one anymore, how do I connect it (the old TC is not connected to modem).  I want to erase it and then use it as either a second hard drive (sired/sirelesly?) or as a hard drive/bridge.  So,
    1.  why doesn't my cmputer see the old TC
    2  once i have solved that, how do I erase the old one
    3.  Can I use the old one as a supplemental hard drive
         a.  wired?
         b. wirelessly?
    4.  Can I use the old one as a range extender?
    I know .. a lot of questions but I would appreciate any help.
    Thanks
    1. Because it is either the same IP as the new one or hidden by being plugged in as a second router.
    To access it, isolate one computer from the existing network and plug it directly by ethernet to a lan port of the TC. Use the erase function in the TC to remove all the content of the hard disk.
    Then go to the internet tab, connection sharing and select off bridged. You can then reconnect the TC to the network.. and the computer as well. The TC will act as bridged device.. getting IP from the main router and should then appear correctly in Airport utility.
    2. I covered in 1. But you just go in airport utility manual setup. disk, and you will see the erase function. You can also set it to bridge and leave the erase until you put it back in the network.. but be careful you erase the right one.
    3. You can use the old TC via wired or wireless.. although I would always stick to wired connection if possible. Speed on wireless is 10x worse than wired.
    Also note the reliability goes down dramatically after 2 years.. a series 1 3 years old or more is ebay fodder unless you want to repair it. Do not trust vital data to it.. when it dies you will have issues recovering it.
    4. Yes, all apple routers will function as wireless extenders. when you do that the ethernet ports turn off so it becomes a purely wireless device.. strange apple decision on what you want to use your TC for.

  • How to create a link to a web page that is connected to the database?

    i am developing a web form in java using Oracle's JDeveloper. i created the form which is connected to the database and now i want to put a link in a page that when clicked it shows the form and populates it if necessary. i have no idea how to do that, can anyone please give me an example or where i can find an example?

    Its really hard to answer this question with this enough information....Which Jdeveloper version? which technology you are using to create this web form ? ADF BC or others
    If 11g then are you aware of Task flows?

  • How can I speed up the connection to the database?

    I am running a JSP application with regular JavaBeans not EJB and connecting to the database through these beans. The connection is set to stay in memory as long as the bean is in session. However when I am running more than 7 sql statements seperatly the execution of the page slows down.
    I have tried using connection pooling but doesn't help much.
    I am not using the JDBC setting in JRUN, I am connecting through the jdbc.odbc drivers provided by the JDK. Basically coded the connection and the connection pool.
    Is there something else that can be done to speed up the execution of the page?
    Thanks in advance

    Thank you all for your input I was trying to work this project to learn JSP so I am not looking at purchasing any drivers right now. That is the reason why I stuck to the JDBC-ODBC Bridge. Are there any other drivers available for MS SQL Servers that are free.
    Jschell,
    That suggests you are taxing the system. It could be >connections. It could also be network, cpu, bus, etc. It >could also be memory, if your app starts swapping to >the hard drive it will get substantially slower.How can i figure out which of the above (i.e. memory, cpu, connections, network) are causing the problem.
    (Presumably you explicitly close your >ResultSets/Statements/Connections when you are >done with them.)You are right about that yes I am closing them at the end of the session, which I think should be after all of the SQL's get executed but I could be wrong it might be openeing a new connection for each SQL which inturn might be the reason for this whole problem. I will take a look into that.
    Thank you all once again.

  • How to change a connection with the database in Runtime?

    How to change a connection with the database in Runtime?
    My connection was made using ADF Business component (ApplicationModule).
    ADF Swing.
    JDeveloper Studio 11.1.1.4.0.

    When deploying ADF applications with database connection, you should be using JDBC data sources configured in the weblogic server.
    You could change the JDBC data sources to a different DB instance or location - by changing the JDBC data source and restarting the weblogic server.
    For more details, check
    http://techiecook.wordpress.com/2010/12/02/oracle-weblogic-adf-datasources/
    Thanks,
    Navaneeth

Maybe you are looking for