JSP连接Mysql数据库

发表于:2007-07-04来源:作者:点击数: 标签:
GRANT select,insert ON jspdb.* to jspuser IDENTIFIED by ''123456''; 代码 % Class.forName(org.gjt.mm. mysql .Driver).newInstance(); String url =jdbc:mysql://localhost:3306/jspdb?user=jspuser password=''123456''; java.sql.Connection connecti

GRANT select,insert ON jspdb.* to jspuser IDENTIFIED by ''123456'';
代码
<%
Class.forName("org.gjt.mm.mysql.Driver").newInstance();
String url ="jdbc:mysql://localhost:3306/jspdb?user=jspuser &password=''123456''";
java.sql.Connection connection = java.sql.DriverManager.getConnection(url);
java.sql.Statement statement =connection.createStatement();
String sql="select * from company";
java.sql.ResultSet rs = statement.executeQuery(sql);
while(rs.next()) {%>
您的第一个字段内容为:<%=rs.getString(1)%> <br>
您的第二个字段内容为:<%=rs.getString(2)%> <br>
<%}%>
<%out.print("数据库操作成功");%>
<%
rs.close();
statement.close();
connection.close();
%>
测试环境为redhat 8.0 下的Resin

原文转自:http://www.ltesting.net