jsp连mysql问题!!!!!!!!! 小弟第一次用jsp连接mysql数据库,都连了快一个礼拜了还是连不上啊,上死火了。请大哥哥或大姐姐们给个指点好吗。 我很笨的,希望能从头教起。 拜托了,如果连上了请吃糖葫芦!!!!! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 JSP文件内容如下:<%@ page contentType="text/html; charset=gb2312" %><%@ page language="java" %><%@ page import="java.sql.*" %><% Connection cConnection; Statement sStatement; ResultSet rQueryResult; ResultSetMetaData rResultSetMetaData; String sSQL = "select user, password from user"; int iColumnCount; cConnection = null; sStatement = null; rQueryResult = null; try { Class.forName("com.mysql.jdbc.Driver").newInstance(); cConnection = DriverManager.getConnection("jdbc:mysql://localhost/mysql?username=root&password=null&useUnicode=true&characterEncoding=gb2312"); try { sStatement = cConnection.createStatement(); try { rQueryResult = sStatement.executeQuery(sSQL); try { rResultSetMetaData = rQueryResult.getMetaData(); try { iColumnCount = rResultSetMetaData.getColumnCount(); out.print("<table border=1 bordercolor=black align='center' width='500'>"); out.print("<tr>"); out.print("<td>" + "user" + "</td>"); out.print("<td>" + "password" + "</td>"); out.print("</tr>"); while(rQueryResult.next()) { out.print("<tr>"); out.print("<td>" + rQueryResult.getString(1) + "</td>"); out.print("<td>" + rQueryResult.getString(2) + "</td>"); out.print("</tr>"); } out.print("</table>"); out.print("<br>"); out.print("数据库操作成功,恭喜你"); } catch (SQLException e) { System.err.println("rResultSetMetaData.getColumnCount():" + e.getMessage()); } } catch (SQLException e) { System.err.println("rQueryResult.getMetaData():" + e.getMessage()); } } catch (SQLException e) { System.err.println("sStatement.executeQuery(sSQL):" + e.getMessage()); } finally { try { if (rQueryResult != null) rQueryResult.close(); } catch (SQLException e) { e.printStackTrace(); } rQueryResult = null; } } catch (SQLException e) { e.printStackTrace(); } finally { try { if (sStatement != null) sStatement.close(); } catch(SQLException e) { e.printStackTrace(); } sStatement = null; } } catch(SQLException e) { e.printStackTrace(); } finally { try { if (cConnection != null) cConnection.close(); } catch(SQLException e) { e.printStackTrace(); } cConnection = null; }%> 如果你的密码为空(即没有密码),试一下把:cConnection = DriverManager.getConnection("jdbc:mysql://localhost/mysql?username=root&password=null&useUnicode=true&characterEncoding=gb2312");改成:cConnection = DriverManager.getConnection("jdbc:mysql://localhost/mysql?username=root&useUnicode=true&characterEncoding=gb2312");即把“&password=null”这选项去掉 你用的MySQL驱动是多少版本的?你的MySQL的版本是多少呀? 存储过程 能否合并 结果集??? key_buffer与innodb_buffer_pool_size的值有冲突吗 求个数据库监控软件。 本地ADO访问速度慢,远程ADO访问速度快,求高手解答 在postgresql如何让一个组里的用户可以拥有对某个数据库里所有的表sel/ins/upd/del/rul权限? mysql lock table的一些疑问 100分求一条查询语句. 大虾们:什么软件实现mysql自动备份比较好。具体如何使用。 怎么样去重? C++查询MySQL数据出现问题,盼指教 ADO访问Mysql乱码问题 MySQL数据库服务器软件版本升级问题?
Connection cConnection;
Statement sStatement;
ResultSet rQueryResult;
ResultSetMetaData rResultSetMetaData;
String sSQL = "select user, password from user";
int iColumnCount; cConnection = null;
sStatement = null;
rQueryResult = null; try {
Class.forName("com.mysql.jdbc.Driver").newInstance();
cConnection = DriverManager.getConnection("jdbc:mysql://localhost/mysql?username=root&password=null&useUnicode=true&characterEncoding=gb2312"); try {
sStatement = cConnection.createStatement();
try {
rQueryResult = sStatement.executeQuery(sSQL); try {
rResultSetMetaData = rQueryResult.getMetaData();
try {
iColumnCount = rResultSetMetaData.getColumnCount(); out.print("<table border=1 bordercolor=black align='center' width='500'>");
out.print("<tr>");
out.print("<td>" + "user" + "</td>");
out.print("<td>" + "password" + "</td>");
out.print("</tr>");
while(rQueryResult.next()) {
out.print("<tr>");
out.print("<td>" + rQueryResult.getString(1) + "</td>");
out.print("<td>" + rQueryResult.getString(2) + "</td>");
out.print("</tr>");
}
out.print("</table>");
out.print("<br>");
out.print("数据库操作成功,恭喜你");
} catch (SQLException e) {
System.err.println("rResultSetMetaData.getColumnCount():" + e.getMessage());
}
} catch (SQLException e) {
System.err.println("rQueryResult.getMetaData():" + e.getMessage());
}
} catch (SQLException e) {
System.err.println("sStatement.executeQuery(sSQL):" + e.getMessage());
} finally {
try {
if (rQueryResult != null)
rQueryResult.close();
} catch (SQLException e) {
e.printStackTrace();
}
rQueryResult = null;
}
} catch (SQLException e) {
e.printStackTrace();
} finally {
try {
if (sStatement != null)
sStatement.close();
} catch(SQLException e) {
e.printStackTrace();
}
sStatement = null;
}
} catch(SQLException e) {
e.printStackTrace();
} finally {
try {
if (cConnection != null)
cConnection.close();
} catch(SQLException e) {
e.printStackTrace();
}
cConnection = null;
}
%>
cConnection = DriverManager.getConnection("jdbc:mysql://localhost/mysql?username=root&password=null&useUnicode=true&characterEncoding=gb2312");
改成:
cConnection = DriverManager.getConnection("jdbc:mysql://localhost/mysql?username=root&useUnicode=true&characterEncoding=gb2312");即把“&password=null”这选项去掉
你的MySQL的版本是多少呀?