Now that Sun has acquired MySQL, the combination of java and MySQL is going to be the next big thing in the market. Today I will present a small tutorial on how you can connect to MySQL using JDBC. This procedure is tested under windows platform with jdk 1.6.
Pre-requisites:-
- JDK- download
- MySQL- download
- JDBC connector - link given below.
- You need to download the driver Connector/J zip from MySQL website. Here is the download link.
- Extract the zip file.
- After extracting you will find a JAR file inside the unzipped directory.
- Copy the JAR file to "jre path"\lib\ext
- Now take the help of the following example to proceed.
import java.sql.*;
public class jdbc_mysql
{
public static void main(String args[])
{
PreparedStatement stmt = null;
ResultSet rs = null;
Connection conn=null;
try
{
Class.forName("com.mysql.jdbc.Driver").newInstance();
conn = DriverManager.getConnection("jdbc:mysql://localhost/dbname?"+
"user=user_name&password=your_password");
stmt=conn.prepareStatement("select * from student where name=?");
stmt.setString(1,args[0]);
rs=stmt.executeQuery();
if(rs.next()==false)
System.out.println("Record not found!!!");
else
{
String s=rs.getString(2);
System.out.println(s);
}
}
catch(Exception e)
{
System.err.println("Exception: " + e.getMessage());
}
}
}
Sorry for the clumsy indentation. It got deformed when I pasted my code in the blogger editor. If you have any further queries please feel free to leave a comment. I will address your query as soon as possible.
Hibernate is a very handy tool. It speeds up your start up and shutdown time. Starting after hibernation brings the computer back to exactly the same state where you left at the time of hibernation.
To hibernate just select
Start->Turn off computer. Now a menu will come showing Stand By, Turn Off, Restart. Press
shift, the "Stand by" will change to "Hibernate". Now click the button, then sit back and watch your computer go to hibernation.
To redirect pages to https always you need to paste the following code to "tomcat_home"\webapps\ROOT\WEB-INF\web.xml

Now restart tomcat. From now on all pages will be redirected to https.
Prerequisites:-
1. JDK
2. Tomcat
For any https (SSL) page a certificate is very necessary. First we will learn generating a keystore, which will contain a certificate chain. We will use the
keytool command from JDK.
1. Goto the command prompt.
2. Type
keytool -genkey -alias tomcat -keyalg RSA (if your path is not set to the java bin directory, please go there and type the command).
3. Now you will prompted for a keystore password give it as
changeit (you can give it different but you will have to make some changes later).
4. Enter the details needed.
5. Now alias password will be aksed. It
must be same as keystore password.
6. After the end of it a keystore will be generated in
"drive":\Documents and Settings\"username"\.keystore
Now configure "tomcat_home"\conf\server.xml, add the following code:-
You are done with your configuration. Save the server.xml file. Restart your tomcat. Now type https://localhost:8443
This should show you the same tomcat homepage but in secured format.
Disclaimer
Experiment with the things mentioned in this blog at your own risk. The author shall not be held responsible for any damages caused to your system by the things mentioned in the blog.
Notice
All logos, trademarks, images used are property of their respective organizations. If any organization has objection to any post regarding use of their property I will happily remove it.