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的版本是多少呀? MySQL中,求一条SQL语句 关于mysql的连接数问题 mysql query browser myi文件丢失 多线程中使用mysql的c api是安全的吗?? 江湖救急::: 帮忙看下这条语句该怎么写 有谁在win2k下用apache-mysql-php4这个软件配置过php,安装完后应该怎么指向? Mysql取各区间的最大值和最小值 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的版本是多少呀?