添加mysql用户
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