|
The steps required to implement serverside java on your Arachno Net hosting account
- 1/ Some basic information: Our JDK is version 1.4
- We use Tomcat 4 java server with which you can implement jsp, servlets and enterprise java beans.
- a/ Tomcat 4.0 will implement the Servlet 2.3 and JSP 1.2 container specifications.Tomcat 4.0 also supports web applications built for the Servlet 2.2 and JSP 1.1
specifications with no changes.
- b/ To have java enabled for your site, please email support@arachnonet.com and request
that it be installed on your site, please provide your username and site url with the request.
- c/ When it is installed a java directory structure will appear in your site root directory, the structure will be like this /java/WEB-INF/classes
- d/ jsp files will go in the /java directory or subdirectories under it, and will be called with the url http://www.yourdomainname.com/java/filename.jsp, it is important to use the www in the URL format as www.yourdomainname.com is your sites context definition within the server.xml file, and therefore no other format will work
- e/ Your web.xml files used to define your servlets go in the /java/WEB-INF directory
- f/ Your servlets (class files will go in the /java/WEB-INF/classes directory and you can call the servlets using http://www.yourdomainname.com/java/servlet/servletname
- 2/ Our JDBC mysql driver is mm.mysql if you wish to use JDBC follow these instructions
- a/ In your control panel use the mysql manager to create your database and user then assign the user to the database.
- Use the connection string given in the mysql manager with the addition of the connection port, please see the example below.
- JDBC Connection C = DriverManager.getConnection( "jdbc:mysql://localhost:3306/database_name?user=something_user&password=xxxxxxxx");
- You can use the sample code below to check your database connection This sample code was made available by thebeastunleashed.com
<%
// ---- configure this for your site
// The URL that will connect to our MySQL server. Syntax: jdbc:TYPE:machine:port/DB_NAME
String url = "jdbc:mysql://localhost:3306/database_name?user=xxx_xxx&password=yyyyy";
// A canned query string
String queryString = "SELECT the_column from your_table_name";
// INSTALL/load the Driver (Vendor specific Code)
try {
Class.forName("org.gjt.mm.mysql.Driver");
} catch(java.lang.ClassNotFoundException e) {
System.out.print("ClassNotFoundException: ");
System.out.println(e.getMessage());
}
// Here's where we start the connection and then submit a request
out.println ("<h1>Connecting to a mySQL database</h1><hr>");
try {
java.sql.Connection con;
java.sql.Statement stmt;
// Establish Connection to the database at URL with usename and password
con = java.sql.DriverManager.getConnection(url);
out.println ("<BR>Ok, connection to the DB worked.");
out.println ("<BR>Let's see if we can retrieve something with: <STRONG>" + queryString +
"</strong>");
// Create a Statement Object
stmt = con.createStatement();
out.println ("<BR><br>Created statement ...");
// Send the query and bind to the result set
java.sql.ResultSet rs = stmt.executeQuery(queryString);
out.println ("<BR><BR>Got result set .. it is " + (rs == null ? " NULL" : "not null")
+ "<BR><br>");
int counter = 0;
while (rs.next()) {
String s = rs.getString("cl_name");
out.println("Column <strong>the_column</strong> for row " + (++counter) + " is " + s +
"<BR>");
}
// Close resources
stmt.close();
con.close();
}
// print out decent error messages
catch(java.sql.SQLException ex) {
out.println("==> SQLException: ");
while (ex != null) {
out.println("Message: " + ex.getMessage () +"<BR>");
out.println("SQLState: " + ex.getSQLState () + "<BR>");
out.println("ErrorCode: " + ex.getErrorCode () + "<BR>");
ex = ex.getNextException();
out.println("<BR>");
}
} catch (Exception e1) {
out.println ("Other exception - " + e1.getMessage ());
}
%>
|