Java Tomcat Hosting

Account specs

Discover the possibilities

Java Environment Setup

How to guides

Pricing & Ordering

Specials

Order Now

 

 

How to work with
Servlets
Java Development Frameworks
Tomcat & Database
Deploying webapps
JSPs and PHPs
Ecommerce and Java
https through Tomcat

 

   

Domain Search: www.

SERVERS & NETWORK  |  SUPPORT  |  WHY OXXUS  |  TESTIMONIALS  |  ABOUT US  |  CONTACT |  ORDER NOW

Working with Database and Tomcat 

MySQL <> JSP connection working example
 

You'll first need to create a database through your control panel.

All these instructions for database set up will also be posted in your initial account activation email.

 


This is an example with org.gjt.mm.mysql.Driver MySQL driver. We also support com.mysql.jdbc.Driver


--------------------------------------------------------------------------------
File 1: dbtest.jsp
<%
String dbhost1 = request.getParameter("dbhost");
String dbname1 = request.getParameter("dbname");
String user1 = request.getParameter("user");
String pass1 = request.getParameter("pass");
if( dbhost1==null )
dbhost1="localhost";
if( dbname1==null )
dbname1="ENTER=HERE-YOUR-DB-NAME";
if( user1==null)
user1="YOUR-USER-NAME";
if( pass1==null )
pass1="MYSQL-PASSWORD";
%>
<form action="dbsubmit.jsp" method=get>
<table>
<tr>
<td>dbhost
<td><input size=60 name="dbhost" type=text value="<%=dbhost1%>">
<tr>
<td>dbname
<td><input size=60 name="dbname" type=text value="<%=dbname1%>">
<tr>
<td>user
<td><input name="user" type=text value="<%=user1%>">
<tr>
<td>password
<td><input name="pass" type=text value="<%=pass1%>">
<tr>
<td colspan="2">
<input type=submit>
</table>
</form>
------------------------------------End of dbtest.jsp
--------------------------------------------------------------------------------

File 2 - dbsubmit.jsp
<%
String dbhost = request.getParameter("dbhost");
String dbname = request.getParameter("dbname");
String user = request.getParameter("user");
String pass = request.getParameter("pass");
String connURL =
"jdbc:mysql://"+dbhost+"/"+dbname+"?user="+user+"&password="+pass;
try
{
Class.forName("org.gjt.mm.mysql.Driver").newInstance();
java.sql.Connection conn = java.sql.DriverManager.getConnection(connURL);
response.getWriter().println("<font color=green><b>");
response.getWriter().println("Connection success!!!");
response.getWriter().println("</b></font>");
}
catch(Exception e)
{
response.getWriter().println("<font color=red><b>[");
response.getWriter().println(e.getMessage());
response.getWriter().println("]<br>");
response.getWriter().println("Connection URL:["+connURL+"]");
response.getWriter().println("</b></font>");
}
%>
<%@include file="dbtest.jsp"%>

--------------------------------End of dbsubmit.jsp





Example web.xml file:

<?xml version = '1.0' encoding = 'windows-1252'?>
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
<description>Empty web.xml file for Web Application </description>
<servlet>
<servlet-name>HelloWorldExample</servlet-name>
<servlet-class>HelloWorldExample</servlet-class>
</servlet>

<servlet-mapping>
<servlet-name>HelloWorldExample</servlet-name>
<url-pattern>/servlet/HelloWorldExample</url-pattern>
</servlet-mapping>

<session-config>
<session-timeout>30</session-timeout>
</session-config>

<mime-mapping>
<extension>html</extension>
<mime-type>text/html</mime-type>
</mime-mapping>

<mime-mapping>
<extension>txt</extension>
<mime-type>text/plain</mime-type>
</mime-mapping>
<welcome-file-list>

<welcome-file>index.jsp</welcome-file>
<welcome-file>index.html</welcome-file>
</welcome-file-list>
</web-app>
 

 

 

 

 

Working with Database and Tomcat

 

 

 

 

 

 

 

 

See list of ALL supported technologies and account features

 

Need further assistance? 

Visit our Java knowledge base or

contact us and we'll be happy to help

 

 



Order with confidence

100% Secure Ordering
Privacy Policy
Money back guarantee

 

Host of choice for 1,500+

Java Developers

 

 Why host with Oxxus
 Customer Testimonials
 Meet the Oxxus Team


Choose your gift
Free domain
Free Unique IP
$$ off hosting fee
Pick your free gift
.........................................

 

It's fast and stable like dedicated server yet it's as affordable as virtual hosting. What is it?

 


 


and go live in just 4hours

 

 

Copyright ® 2003-2007 Oxxus.Net * USA * UK * AUP * Best web hosting solutions from internets leading web hosting provider * Tutorials * Resources * Blog * FAQ
JSP hosting * Java hosting * Servlet hosting * J2EE hosting * Tomcat hosting * PHP hosting * SSL hosting