How to Connect GoDaddy Java to MySQL
Java technology lets Web devlopers and software engineers create dynamic Web pages in XML, HTML and Java using the JavaServer Pages, or JSP, technology. Subscribers of GoDaddy hosting services can connect their JSP Web pages to a MySQL database by using the correct code. A MySQL database is required to provide the dynamic data used in the Java pages.
Instructions
-
-
1
Log in to your GoDaddy Web hosting account using an FTP client.
-
2
Copy and paste the desired JSP file from the list of available files to your desktop.
-
-
3
Click “Start,” “All Programs” and select “Notepad.”
-
4
Click “File” and select “Open.” Select the JSP file you copied to your desktop and click “Open.”
-
5
Copy and paste the following code into the body of your JSP file between the <body> and </body> tags:
<%@ page contentType="text/html; charset=iso-8859-1" language="java"
import="java.sql.*" errorPage="" %>
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body><h1>GDtest
</h1>
<% String url = "jdbc:mysql://mysql server:3306/databasename";
String user= "";
String pass= "";
try{
Class.forName ("com.mysql.jdbc.Driver").newInstance ();
Connection conn = DriverManager.getConnection(url, user, pass);
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery("mysql statment");while(rs.next())
{
%>
<table> <tr>
<td><%= rs.getString("fname") %></td>
<td><%= rs.getString("lname") %></td>
</tr></table>
<%}
rs.close();
conn.close();
}catch(Exception e)
{
out.println(e.toString());
}
%> -
6
Click “File” and then “Save.”
-
7
Upload the file to your GoDaddy Web hosting account using an FTP client.
-
1