Monday, December 8, 2014

Tutorial Write-Up Blog Post Assignment
Ryan Chandler, IT210B

How can JSP be used to connect to a MySQL database?
How do I set up Tomcat and MySQL on Linux?

Introduction

If you are looking to retrieve and store images, add login/logout functionality, or remove content for your website, knowing what JSP and MySQL are and how they work will be incredibly helpful! For this tutorial, you will explore JSP, MySQL, and Tomcat - what they are, how each works, and how to set them up.  You will also understand some common issues that occur during the process of implementing each of them.

For reference, let’s discuss briefly what each of these tools are.

JSP - Java Server Pages. JSP is a technology created by Sun Microsystems that allows Java to be run on a server. Because Java is one of the most widely used programming languages in the world, it can add familiarity to the experience of programming on a server. It can be used on HTML web pages to create dynamic experiences

MySQL - an open-source relational database. MySQL databases are commonly used to store textual information that must be accessed frequently. The information is accessed using SQL query statements that ask the database for the necessary information. Because the data is stored relationally, there is a lot of flexibility to be able to manipulate and access or save information where and when you need it.

Tomcat - a web server. Apache Tomcat is the brains that makes up your server. It is configured to be able to run JSP-programmed pages, so therefore it will work perfectly as our server software. The Tomcat server is where your actual JSP pages will be stored and run from.

Each of these tools will work together to create a seamless experience for users of your website. Tomcat will run your JSP pages, which will have access to your MySQL database information.

You will first go over how to set up an Apache Tomcat server. You will then set up a MySQL database. Finally, you will learn a bit of JSP syntax, focusing on how to connect your webpages to your MySQL database. This tutorial will be using a Linux Ubuntu operating system to perform these tasks.


Tutorial

Part 1: Setting up your Tomcat server

Much of setting up your Tomcat server will be done through the Linux terminal. We’ll begin by installing necessary pieces of information. First, let’s make sure your installer is updated properly by typing into your terminal:

sudo apt-get update

Pressing enter will update your apt-get, which will serve as the installer for all the packages you will have to install. Once that is finished, continue by installing the rest of the necessary drivers with these commands:

sudo apt-get install tomcat6
sudo apt-get install tomcat6-admin
sudo apt-get install tomcat6-user

You may have to type a ‘Y’ into your terminal to approve the installation of your Tomcat server. After these have finished installing, you have the core to your Tomcat server running! In order to make your server compatible with your JSP pages later, you’ll now need to make sure your server is configured for the version of Java you currently have installed. Do this by running the command in your terminal:

java -version

If java is not installed, you can install the latest version here. If it is installed, something like this should pop up:

Java version “1.6.0_20”

Remember this version number! Copy and paste it somewhere if you have to. In order to make sure that you have a current version of Java, go ahead and type in this command:

sudo apt-get install openjdk-6-jdk

Tomcat needs to know where you just installed your Java (Otherwise when it tries to run your JSP pages it will be looking for the instructions in the wrong place!), so you will need to change a configuration file for your tomcat server. This file can be opened by typing:

sudo vim /etc/default/tomcat6

This will open up your configuration file for tomcat. Press the letter ‘i’ to edit text, and find the line that looks like this:

#JAVA_HOME=/usr/lib/jvm/openjdk-6-jdk

and change it to this:

JAVA_HOME=/usr/lib/jvm/java-6-openjdk

Press esc on your keyboard, then type :wq and press enter to save the changes made to the file. Congratulations, your Tomcat server is now configured to run your Java pages! Next we have to configure it to allow access to the MySQL database you will set up. Start by opening another Tomcat configuration file:

sudo vim /etc/tomcat6/policy.d/03catalina.policy

In order to allow access to MySQL, add these lines to the very end of the file:

grant {
permission java.net.AllPermission;
permission java.net.SocketPermission “localhost:3306”, “connect”;
};

As you can see from reading the code, you are giving permission for Tomcat to access different things, in this case access to your MySQL database. Finally, your Tomcat server needs to have access to a .jar file. The file can be found here. Pick a place to save the file. Back in the terminal, get to the directory your .jar file resides and copy it into the directory it is required for Tomcat:

cd /[filepath where the .jar file is]/[folder]
sudo cp -r mysql-connector-java-5.[tab key] /usr/share/tomcat6/lib/

In order to make all these configurations apply to the Tomcat server, the server must be rebooted. This can also be done in the terminal:

sudo /etc/init.d/tomcat6 restart

Make sure everything is working by typing http://localhost:8080 into your favorite web browser. If something like Figure 1 shows up, congratulations! Your Tomcat server is now live!



tomcatworks.png
Figure 1: Tomcat default page. It works!

Part 2: Setting up a MySQL database

Now that Tomcat is running, a MySQL database is required for us to connect to! Setting up a MySQL database is very similar to creating your Tomcat server. This time, tasksel will be the tool used to install the needed packages. Type sudo tasksel into the terminal. For the purposes of this tutorial you will only need to install the OpenSSH server, the LAMP server, and the Print server. When prompted, type in a password for your MySQL “root” user. You will use this password often, so don’t forget it!

To install the remaining packages, use the apt-get commandused earlier:

sudo apt-get install phpmyadmin
sudo apt-get install mysql-client
sudo apt-get install libapache2-mod-auth-mysql

To check and make sure our MySQL database is working correctly, type http://localhost/phpmyadmin into your favorite web browser. If something akin to Figure 2 pops up, the installation was successful!

mysqlworks.png
Figure 2: MySQL works!

Part 3: JSP - Connecting to MySQL

You have now created a foundation upon which you can build a successful webpage! In order to understand how a simple JSP page works, you can start by creating a very simple JSP page of your own. Open up a new file in a simple text editor. Gedit comes with Linux and is a simple choice! As discussed earlier, JSP pages are used on HTML pages to add additional functionality. You can see some of this functionality by playing around with a simple HTML page.

<html><body><p>Hello World!</p></body></html>

This file looks a lot like a standard HTML file for sure! Save the file as hello.jsp in the /var/lib/tomcat6/webapps/ROOT directory. The page is simple - see Figure 3.
hello.png
Figure 3: hello.jsp

You want to turn this simple html page into a dynamic html page! This can be done by utilizing JSP’s functionality for MySQL databases. When you saved the file as a .jsp file, it gave it access to use Java on your webpage. Whenever you’d like to use Java code, embed it in <% [Java code] %> tags. Page imports are done using <%@ [import statement] %>. This can give a lot of flexibility to your webpage!

In order to run MySQL queries on your webpage, your page must import a few java utilities, then set up some Connection variables. Right after your <html> tag on your webpage, add these lines of code:

<%@ page import="java.util.*" %>
<%@ page import="javax.sql.*" %>

This will import the necessary drivers that Java has on hand to deal with SQL queries. Next, we’ll need to add some lines of code that will hold both the information to retrieve and the information to connect to the MySQL database:

<%
java.sql.Connection con;
java.sql.Statement s;
java.sql.ResultSet rs;

String url = "jdbc:mysql://localhost:3306/it210b";
String id = "root";
String pass = "[your MySQL password]";
Class.forName("com.mysql.jdbc.Driver");
%>

Finally, call the methods that are held in the java.sql library that allow connection to the MySQL database:

<%
try {
con = java.sql.DriverManager.getConnection(url, id, pass);
s = con.createStatement();
rs = s.executeQuery("SELECT * FROM text");
while(rs.next()) {
out.print(rs.getString(0));
}
con.close();
} catch(Exception e) {
out.print(e);
}%>

Taking a closer look at the code, we can see on the most outside level that we are trying to make the connection. If that doesn’t work, we’ll print out the error to the user. If there’s no error, a connection will be made with the database, and then an SQL query will be executed to select all of the information from the table “text”. It will then print out the information in the first column of the text table for every row in the table. In this case, the table only includes one row with one column that has the text “Hello World!”.

Save and open hello.js with your favorite webbrowser. Congratulations, a connection with MySQL has been made!

hello.png
Figure 4: MySQL query complete! hello.jsp

Additional Resources

Here are some resources to websites you might find helpful:

http://www.jsptut.com/ - This is a website that contains a TON of helpful resources for learning basic JSP. Whether you’re new to Java or a veteran, there’s interesting information here that will help you out exponentially.

http://dev.mysql.com/doc/refman/5.6/en/examples.html - MySQL queries can be confusing and difficult sometimes. This is a helpful sheet of examples for basic SQL queries you will use often.

http://www.mulesoft.com/tcat/tomcat-60 - Sometimes there are problems with installing Tomcat6. This website is very helpful for making sure your installation works properly and fixing any mistakes you may have made

http://www.siteground.com/tutorials/phpmyadmin/ - phpmyadmin is a very effective tool for managing your MySQL database - this site is very helpful in figuring out its ins and outs!

Wednesday, December 14, 2011

Final Exam: Part 2--

Within the four groups of knowledge we studied, mentally I divide them into two groups. The hard line falls between oral knowledge and written knowledge. The more prehistoric units of knowledge always seemed to overlap, and I had trouble drawing a fine line between what I would definitively call folk and what I would call oral. The more modern conventions, on the other hand, have a finite definition; written knowledge no longer includes using vocal chords, and print includes using a type face. While important in antiquity,these later conventions of knowledge are teetering on the edge of going obsolete because of the new conventions that the digital age is thrusting upon us.

Tuesday, December 13, 2011

Final Blog: Blurred

When studying a subject, it is often convenient to make categories and divisions of the knowledge. This helps us to understand and more easily remember what we have learned. At the same time, it is important to remember that our artificially-created divisions are just that--artificial. Real examples may fit into more than one category, or no category at all. While there may seem to be clear distinctions between folk, oral, written, and printed knowledge, the lines are really very blurred.

The Chronologic Progression of the Units of Knowledge

Throughout the course of the semester I have noticed the progression of the units in class. These knowledge units build off one another and each have a specific area that they are used in a culture. Folk knowledge is chronologically first because of the minimal requirements needed for it to be used. Oral knowledge builds off of folk knowledge because it is basically folk knowledge but is disseminated publicly. Written knowledge further builds off these two since it was used to write down folk and oral knowledge so that they would not be forgotten. Print knowledge is written knowledge that is massed produced and easily accessible to the world at large.
As I have posted about folk knowledge and have read others’ posts, I have noticed that folk knowledge is taught mostly in the home and is most important for children. Some folk knowledge posted on the blog was my post on brushing teeth, or Alyssa’s post on midwifery. In my folk knowledge group during today’s salon we agreed that things such as rituals and traditions are folk knowledge. Things such as when a boy becomes a man through rite of passage or marriage are folk knowledge and have different meanings and traditions in different cultures.
Oral knowledge builds off folk knowledge. As cultures became more advanced individuals and groups (bards, Greek philosophers, etc.) traveled throughout their country disseminating knowledge that they had gathered. Tales of Gods and heroes and different philosophical ideas were some of the knowledge that was disseminated orally. Diane’s post on Homer’s epics and Kody’s post on prayer are examples of oral knowledge. During the salon my group and I discovered that before things were written down most government, religious and civil matters were of an oral nature. Heralds are a good example of this. They were king’s messengers who were sent to give proclamations.
Written knowledge is very connected to oral knowledge as compared to the other knowledge units. During the time of the Greeks and Romans, Oral knowledge reached its greatest zenith through great orators like Julius Caesar, Cicero, Plato and Socrates. Also, written knowledge grew just as rapidly. Massive libraries in Rome and Alexandria were established. Monuments with written text also reached their zenith during this time period. Alyssa’s post on Why did Plato Write? and Kody’s post on medicine and writing show the importance of written knowledge and its connection to oral knowledge.
Print knowledge is very similar to written knowledge with several key differences. With the invention of print books could be mass-produced, lowering the cost. With the lowering of cost, subjects that did not have as much priority, when knowledge had to written by hand, could now be published. Also, the perusal of knowledge became a much more individual pastime. Before, books were owned by the elite and the Catholic church. Common people had to listen to them to get information and had to take their word that what they were saying was true. Now, almost everyone has access through printed material. In my salon group I brought up an interesting subject that had to do with my civilization. My civilization was the Jewish nation and with the invention of the printing press the Jewish scholars had to debate whether or not the Torah should be allowed to be printed. Before, the Torah was written by hand by one person from start to finish. This ensured that copies were pure in form and that they were written by a holy individual. In the end, they decided that it was okay as long as some Torahs were written by hand. It is interesting to compare this to the Bible. Christians were very anxious to have the Bible printed and distributed to the general population.
This class has opened my eyes to a world I had not noticed before—the world of the institutions of knowledge. Before this class I had the narrow-minded view that everything came from Google and Wikipedia. Now I understand that I have learned so much from so many different sources, some very ancient in origin. Never again will I look at the acquisition of knowledge the same again.

Final Blog Post

       Folk knowledge is characterized as practical knowledge or survival skills for living within a society. Sharing folk knowledge is the least formal of all knowledge types, making it the easiest to break down learning or interpersonal barriers and form bonds through sharing it. Sharing folk knowledge is not the only way or even the best way to learn and work together, though. Despite claims that other forms of knowledge are less bonding, folk knowledge does not accommodate collaboration and building community more than other types of knowledge, it simply takes less effort to form a community around sharing folk knowledge because folk knowledge involves the lowest common denominator and thereby attracts the largest number of people.

The Final of the Final- Oral Knowledge and Religion

The mediums of knowledgeconsistently change, and slowly and bring about a tradition to those that use them.Regardless of these changes, however, the previous forms of knowledge are neverfully abandoned. This was brought up in a discussion with Lauren and Summer aswe discussed the pros and cons of the transitions between knowledge mediums. Thetransition from oral knowledge to written knowledge within medicine technicallyoccurred thousands of years ago, but yet we still see both forms in our livestoday. In regards to religion, it is a nearly impossible challenge to pick amedium that is superior to others based on effects that it has had on religion because of it being such a vast topic spanning over thousands ofyears. However, there are many major events within the history of religion thatare based around an oral presentation or an oral event. Despite the fact that theBook of Mormon has and will continue to flood the earth, oral knowledge hasbeen most influential in religious practices due to the fact that major religiouschanges are brought about in an oral fashion including monumental speeches madein past times.

Final Exam: Part 1--

Unit 1: Folk Knowledge
Self-directed learning
My blogging consisted of tales of music and manners. We were just starting the class, so I wasn't exactly sure what exactly I was looking for as a self-directed learner. Folk knowledge started for me as a kind of foreign subject, one which was really hard to define and I was never really sure where to draw the line between it and other forms of communicating knowledge. My learning brought me to a more clear understanding of just where folk knowledge lies and effects every inkling of our lives. Also, this.

Others' blogging
Alysssa's tattoo post seems to be a common choice for us as a group, but for good reason. I think the unique subject drew eyes immediately. There was also a post on trumpet playing - as a trumpet player myself, I remember seeing the post and actually being able to relate to what was being said.

Collaborative learning

Seeing the thought process of others in folk knowledge especially was important I feel because of how collaborative (in person) the folk knowledge medium is innate of itself. Other than the blog posts already spoken of, the process of getting to know our core group started here. I don't remember an exact meeting other than sitting with each other in class, but it was fun to get to know some people better.

Projects / Activities
Justin taught me how to catch quarters. That was a fun evening. Then, I taught my roommate to competitive pokemon battle. As silly as both of those sound, I think it was the project that helped me most fully find my definition of folk knowledge. While not necessarily things you could make a living on or even use practically, I figured out that lots of folk knowledge is in place for the sole reason of humans being social beings. They provide ways to fit in to the current society.

Unit 2: Oral Knowledge
Self-directed learning
I got assigned the Celts. The Celtic language was actually really interesting to study, and I found a lot of nuances and connections to the modern day that I didn't think still existed. Specifically, I remember being amazed at the influence the Celtic bards had - they basically controlled all of the culture of the Ireland area. The wars were also fun to study about, but they were less orally-knowledgely-applicable-(ly?).


Others' blogging
I remember Diane's troubles and frustration with the Slavs - the lack of information seemed to be pretty overwhelming at the time. The Romans and Hittites were also taken as pet projects, and I recall Kody posting about the final and how it had seemed silly at first but he had come to appreciate the significance it had.


Collaborative learning
I actually had so much to comment on this unit that I wrote an extra blog post outlining my thoughts and connections between oral knowledge and a book that I have sitting up in my dorm. Much in the same way that I got the most out of the folk knowledge unit by speaking in class with the others, I felt like I got the most out of this unit by collaborating in our blog medium, "speaking" with each other and sharing thoughts.


Projects / Activities
The speech. I'm an awful actor, an awful speaker, and it goes to show in my performance during our class video. Even so, I thought the experience was uplifting and informative. Seeing King Benjamin's speech run live really hit me hard just how much oral knowledge can shape a people's way of life, especially after seeing what it did for the Nephites years after he died even.

Unit 3: Written Knowledge
Self-directed learning
My self-directed learning during written knowledge didn't necessarily manifest itself in certain blog posts during this unit, but you'll just have to trust me that I did learn but had a really bad overload mixed with a hint of writer's block. I decided since I already had a really strong base going with the Celts, I'd keep researching into their language, which turned out to be okay since our final ended up being an precursor to the Goidelic I'd been studying - Ogham.


Others' blogging
We lost a group member here (Amanda :( ) so we lost some content being added to the blog. Alyssa's influx of knowledge on the Roman's really was pretty amazing though, and her post on C really klued me in on a lot of kool stuff.


Collaborative learning
While I didn't really get the chance to blog that much during this unit, I still followed the progress of the others in their learning and tried to chime in a couple times. Writing about writing to me felt like discussion of a lot of semantics and such, so I really never felt all too inclined to be super interested (sorry, but English was never my favorite class).


Projects / Activities
Even so, getting ready and doing the final project with team misc. gave me an appreciation for the scale of how much of our historical record would not be here or would not be accurate without the concrete writing. And when I  say concrete writing, I mean that quite literally. Carving words in stone was quite the task, but with the help of my teammates and the familiarity of the subject in question (again, I had researched Ogham a bit in my personal studies) we got the project done in an admirable fashion. 

Unit 4: Print Knowledge
Self-directed learning
My first trip to the library ever was when this unit started. Blogs seemed to elude me but I found the most interest in Chinese and the other Far East countries. The now-esteemed fifth floor was my guide to everything I needed for this unit, from Korean culture and how printing affected it to paper exports and how Europe was led to the Gutenburg press by Asian knowledge. Of all the units, I think I learned the most flat-out fact in print.

Others' blogging
As people buckled down in preparation for finals week and such, I didn't necessarily see the quality in blogs drop but I felt like the need to interact was further down. Not to say that there weren't some cool posts, such as Alyssa's post on how the press and reading were connected, but I just generally wasn't struck by what others were saying as much as what I was studying on my own along with the pile of homework I had been stuck with in the rest of my classes.


Collaborative learning

To be honest, this unit seemed to be a bit more solo-queue. Each person really did their own thing, though I suppose I did manage to communicate with one of my fellow assigned group members to ensure our topics didn't overlap for the essay. It was a refreshing moment in an otherwise individual set of projects and quest for knowledge. My friends were the authors of the websites and books, my study partner the fifth-floor shelves.

Projects / Activities
I wrote my essay on what I had spent the most time in the library studying about. I set out to prove that the culture in the Far East was tailor-made to be the basis of printing, and so it was that they were the beginnings of the change to printing from writing. While not as crazy (Please let this be a normal field trip. With the Frizz? No way! awww...) as some of our other projects, I kinda felt like it was a nice break from the out of the ordinary stuff we had been doing. Just a straight, this is what I know, and now you can know it too, essay that I could clearly state my thoughts on the unit.