1.下载JDBC驱动程序
www.mysql.com/downloads/中寻找connectors, 然后网页左侧有connector/J 点击会出现供选择的tar.gz和zip文件下载
下载.tar.gz文件
2.展开刚刚下载的文件(mysql-connector-java-5.0.6.tar.gz)
tar zxvf mysql-connector-java-5.0.6.tar.gz
3.配置连接文件
将刚刚展开的mysql-connector-java-5.0.6 中的mysql-connector-java-5.0.6-bin.jar文件拷贝到上面安装的jdk 和 tomcat下的lib文件夹中
cd mysql-connector-java-5.0.6
cp ./mysql-connector-java-5.0.6-bin.jar ~/jdk/lib
cp ./mysql-connector-java-5.0.6-bin.jar ~/tomcat/lib
4.在编写jsp过程中连接数据库可以用以下格式:
Class.forName("com.mysql.jdbc.Driver").newInstance();
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost/数据库名","用户名","密码");
Statement stmt = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,
ResultSet.CONCUR_UPDATABLE);
String sql = "select * from 数据库名";
ResultSet rs = stmt.executeQuery(sql);