论坛首页 入门技术论坛

mysql+jsp配置测试

浏览 2347 次
该帖已经被评为新手帖
作者 正文
   发表时间:2008-03-25  

首先是mysql的下载地址:

http://power4.onlinedown.net/down/mysql-5.0.41-win32.zip

l的图形化配置工具,browser以及administration都在这里里面 

http://dev.mysql.com/get/Downloads/MySQLGUITools/mysql-gui-tools-5.0-r12-win32.msi/from/http://ftp.iij.ad.jp/pub/db/mysql/

mysql的jdbc驱动下载地址:

http://dev.mysql.com/get/Downloads/Connector-J/mysql-connector-java-5.0.8.zip/from/http://mysqlmirror.netandhost.in

jdk1.5的下载地址:

http://192.18.108.137/ECom/EComTicketServlet/BEGINBB56F7CE2C6C6E95AE076D1BD6C64B94/-2147483648/2537678367/1/869090/868922/2537678367/2ts+/westCoastFSEND/jdk-1.5.0_14-oth-JPR/jdk-1.5.0_14-oth-JPR:3/jdk-1_5_0_14-windows-i586-p.exe

mysql+jsp测试的程序如下,关于数据库自己创建,easy!

<%@ page contentType="text/html; charset=gb2312"%>
<%@ page language="java"%>
<%@ page import="com.mysql.jdbc.Driver"%>
<%@ page import="java.sql.*"%>
<%
 //驱动程序名
 String driverName = "com.mysql.jdbc.Driver";
 //数据库用户名
 String userName = "root";
 //密码
 String userPasswd = "123";
 //数据库名
 String dbName = "mydb";
 //表名
 String tableName = "users";
 //联结字符串
 String url = "jdbc:mysql://localhost/" + dbName + "?user="
   + userName + "&password=" + userPasswd;
 Class.forName("com.mysql.jdbc.Driver").newInstance();
 Connection connection = DriverManager.getConnection(url);
 Statement statement = connection.createStatement();
 String sql = "SELECT * FROM " + tableName;
 ResultSet rs = statement.executeQuery(sql);
 //获得数据结果集合
 ResultSetMetaData rmeta = rs.getMetaData();
 //确定数据集的列数,亦字段数
 int numColumns = rmeta.getColumnCount();
 // 输出每一个数据值
 out.print("id");
 out.print("|");
 out.print("num");
 out.print("<br>");
 while (rs.next()) {
  out.print(rs.getString(1) + " ");
  out.print("|");
  out.print(rs.getString(2));
 out.print("<br>");
 }
 out.print("<br>");
 out.print("数据库操作成功,恭喜你");
 rs.close();
 statement.close();
 connection.close();
%>

后来,在官方文档看到了一些话,应该是mysql+web的jdbc驱动的指导了 ,

地址在这里:

http://dev.mysql.com/doc/refman/5.0/en/connector-mxj-install-jboss.html

复制如下:

http://dev.mysql.com/doc/refman/5.0/en/connector-mxj-install-jboss.html

1.Download Connector/MXJ and copy the connector-mxj.jar file to the $JBOSS_HOME/server/default/lib directory.

If you are using Connector/MXJ v5.0.4 or later you will also need to copy the connector-mxj-db-files.jar file to

$JBOSS_HOME/server/default/lib.

2.Download Connector/J and copy the mysql-connector-java-5.0.4-bin.jar file to the $JBOSS_HOME/server/default/lib directory.

3.Create an MBean service xml file in the $JBOSS_HOME/server/default/deploy directory with any attributes set, for instance

the datadir and autostart.

4.Set the JDBC parameters of your web application to use:

String driver = "com.mysql.jdbc.Driver";
String url = "jdbc:mysql:///test?propertiesTransform="+
             "com.mysql.management.jmx.ConnectorMXJPropertiesTransform";
String user = "root";
String password = "";
Class.forName(driver);
Connection conn = DriverManager.getConnection(url, user, password);


You may wish to create a separate users and database table spaces for each application, rather than using "root and test".

We highly suggest having a routine backup procedure for backing up the database files in the datadir.

 

论坛首页 入门技术版

跳转论坛:
Global site tag (gtag.js) - Google Analytics