Download presentation
Presentation is loading. Please wait.
2
Programming for the Web Assignment 1 Help Mark Johnson
3
Things you this will help you with… Software to install at home –Java –Eclipse –Tomcat –MySQL
4
Installing Java The version of Java we will use is 1.4.1 There are two forms in which Java can be installed –Software development kit (sdk) –Runtime environment (jre) We want the SDK Click here to install correct versionhere
5
Installing TomCat If you install Java using the previous method it should set up the JAVA_HOME environment variable If not (you will be able to tell if the following doesn’t work), go to the System control panel and set a variable JAVA_HOME to point to where you have installed TomCat Click here to download the correct version of TomCathere
6
Installing Eclipse You can install the latest version of Eclipse Find it from http://www.eclipse.orghttp://www.eclipse.org This will allow you to do the initial programming exercises in Java that we did (and will check syntax, etc)
7
Installing MySQL The version of MySQL we are using is 4.1 Download it from here and double-click to installhere Don’t choose a password! To run the MySQL server, browse to C:\mysql\bin Unlike in the lesson, you can run the program ‘winmysqladmin’ which will run the server within windows (not DOS) Check it’s working by using the Command window (run cmd) –Type C: –Type cd \mysql\bin –Type mysql –u root
8
Installing Java MySQL connectivity Finally, we need the file which connects Java to MySQL This can be found at the MySQL website and it’s called Connector/J Actually, what you need is one file within the Connector/J download called Download that file from herehere Copy the file to the Common\lib directory in TomCat –So if you installed Tomcat at C:\program files\Apache\Tomcat4.1, the file should be copied to C:\program files\Apache\Tomcat4.1\Commons\lib Start TomCat by running start.bat in your TomCat bin directory (probably C:\program files\Apache\Tomcat4.1\bin) Check it works by pointing your web browser to http://127.0.0.1:8080http://127.0.0.1:8080 Any problems, contact me!
9
Making a connection to a database So we now need to write the.jsp code to connect to the database The code is: <% String connectionURL = "jdbc:mysql://localhost:3306/mytest?user=;password="; Connection connection = null; Statement statement = null; ResultSet rs = null; Class.forName("com.mysql.jdbc.Driver").newInstance(); connection = DriverManager.getConnection(connectionURL, "", ""); statement = connection.createStatement(); rs = statement.executeQuery("SELECT * FROM urls"); while (rs.next()) { out.println(rs.getString("url")+" "); } rs.close(); %>
10
Outputting results This code will simply output results, with the file encoded as XML It needs to output ‘proper’ XML, so the lines while (rs.next()) { out.println(rs.getString("url")+" "); } Need to change so that the output is wrapped by … etc
11
Where to go next… 1.Install the software as instructed 2.Set up the database (as in the practical) 3.Copy the code for the.jsp file and create a new.jsp file in tomcat\webapps\ROOT\ and get it to work 4.Run tomcat from http://127.0.0.1:8080 check it workshttp://127.0.0.1:8080 5.Load up page at http://127.0.0.1:8080/myfile.jsp (if the file you created in 3 is called myfile.jsp) http://127.0.0.1:8080/myfile.jsp
12
Quick revision for those who didn’t do the practical this week Creating a database Download and install mysql from location specified in slide 6slide 6 Find and run the file C:\mysql\bin\mysqld Load a DOS (cmd) window In DOS window type C: Type cd \mysql\bin Type mysql You will now be in mysql Type create database mytest; Type use mytest; Type create table test (url text, description text, mydate date); Type insert into test values (“http://127.0.0.1:8080”, “tomcat”, “2007/5/1”); Type select * from test; So now when you use code in slide 8, you will use a connection string that reads: "jdbc:mysql://localhost:3306/mytest?user=;password=";slide 8 And your select string will read “select * from test” (your table name)
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.