java.sql.SQLException: No suitable driver found for jdbc://localhost:8080/test

卡胖 2011-12-04 01:47:31
myEclips 中得驱动已经集成了,打不开JSP页面,代码没显示错误,怎么回事呢?
<%@ page language="java" import="java.util.*"
contentType="text/html; charset=gb2312" pageEncoding="UTF-8"%>
<%@page import="java.sql.*"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme() + "://"
+ request.getServerName() + ":" + request.getServerPort()
+ path + "/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">

<title>My JSP 'jdbcinjsp.jsp' starting page</title>

<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->

</head>

<body>
<%
try {
//装载驱动程序
// Class.forName(com.mysql.jdbc.Driver);
String driverClass = "com.mysql.jdbc.Driver";
//连接字符串
String url = "jdbc:mysql://localhost:8080/mydata";
//建立连接

Connection conn = DriverManager.getConnection(
"jdbc://localhost:8080/test", "root", "root");

out.print("<h4>1.向表中 插入三个新员工记录 </h4>");
PreparedStatement pstmtInsert = conn
.prepareStatement("insert into employee values(?,?,?,?)");

pstmtInsert.setString(1, "Zhou");
pstmtInsert.setString(2, "Kai");
pstmtInsert.setInt(3, 45);
pstmtInsert.setString(4, "no.45 Changgan Road");
pstmtInsert.setString(5, "Beijing");

if(pstmtInsert.executeUpdate()!=0)
out.println("新增加第一个员工成功<br>");
else
out.println("新增加第一个员工失败 <br>");

pstmtInsert.setString(1, "Zhu");
pstmtInsert.setString(2, "Lin");
pstmtInsert.setInt(3, 28);
pstmtInsert.setString(4, "no.28 Zhonghua Road");
pstmtInsert.setString(5, "Beijing");
if (pstmtInsert.executeUpdate() != 0)
out.println("新增加第二个员工成功<br>");
else
out.println("新增加第二个员工失败 <br>");
pstmtInsert.close();
//使用 Statement
Statement stmtInsert = conn.createStatement();

String sql = "insert into employee values('He','Hai',35,'no.23 Garden Road','Shanghai')";
int result = stmtInsert.executeUpdate(sql);
if (result != 0)
out.println("新增加第三个员工成功 <br>");
else
out.println("新增加第三个员工失败 <br>");
stmtInsert.close();

out.println("<h4>2.修改最后一个插入的员工 He Hai 的年龄为50岁 </h4>");
Statement stmtUpdate = conn.createStatement();
sql = "update employee set age=50 where firstname='He'";
result = stmtUpdate.executeUpdate(sql);
if (result != 0)
out.println("修改年龄成功 <br>");
else
out.println("修改年龄失败 <br>");
stmtUpdate.close();

out.print("<h4>3.查询所有员工记录 </h4>");
%>
<table border=1 cellspacing=1>
<tr>
<td>
firstname
</td>
<td>
lastname
</td>
<td>
age
</td>
<td>
address
</td>
<
<td>
city
</td>
</tr>
<%
Statement stmtSelect = conn.createStatement();
ResultSet rs = stmtSelect
.executeQuery("select * from employee");

while (rs != null && rs.next()) {
out.print("<tr><td>" + rs.getString("firstname") + "</td>");
out.print("<td>" + rs.getString("lastname") + "</td>");
out.print("<td>" + rs.getInt("age") + "</td>");
out.print("<td>" + rs.getString("address") + "</td>");
out.print("<td>" + rs.getString("city") + "</td></tr>");

}
rs.close();
stmtSelect.close();
%>
</table>
<%
out.print("<h4>4.删除最后一个的员工 He Hai</h4>");
Statement stmtDelete = conn.createStatement();
sql = "delete from employee where firstname=='He'";
result = stmtDelete.executeUpdate(sql);
if (result != 0)
out.println("删除成功 <br>");
else
out.println("删除失败 <br>");
stmtDelete.close();
conn.close();
}/* catch(ClassNotFoundException cnfe){
out.print(cnfe);
}*/catch (SQLException sqle) {
out.print(sqle);
} catch (Exception e) {
out.print(e);
}
%>
</body>
</html>
...全文
766 17 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
17 条回复
切换为时间正序
请发表友善的回复…
发表回复
专坑队友 2011-12-06
  • 打赏
  • 举报
回复
你把驱动信息都注释了 肯定找不到啊
BUG弄潮儿 2011-12-05
  • 打赏
  • 举报
回复
com.mysql.jdbc.Driver
驱动版本不正确吧
mingying12 2011-12-05
  • 打赏
  • 举报
回复
// Class.forName(com.mysql.jdbc.Driver);
把注释去掉 将括号里面的字符串用引号引起来
还有就是String url = "jdbc:mysql://localhost:3306/xinchuangruanjian";

和下面那句不是重复的吗?
chabale 2011-12-05
  • 打赏
  • 举报
回复
驱动问题,是不是jar包导入有问题,请检查jar包。。。
卡胖 2011-12-05
  • 打赏
  • 举报
回复
[Quote=引用 9 楼 tnjun123456 的回复:]
Class.forName(com.mysql.jdbc.Driver);
这个为什么要注释?
还有String url不知道是做什么····
[/Quote]
String url这个没用,是的
卡胖 2011-12-05
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 chituozhilu 的回复:]
你的WEB.xml放错位置了把!兄弟
[/Quote]
兄弟,我这个没错
卡胖 2011-12-05
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 scrack 的回复:]
// Class.forName(com.mysql.jdbc.Driver);

你为什么要注释
[/Quote]
String driverClass = "com.mysql.jdbc.Driver";
这两个作用是一样的所以就注释了
chituozhilu 2011-12-04
  • 打赏
  • 举报
回复
给你个链接数据库的!package com.fc.struts2;

import java.sql.*;

public class DataBase {
public static Connection conn = null;
public static Statement stmt = null;
public static ResultSet rs = null;

public static Connection getConnection() {
String url = "jdbc:mysql://localhost:3306/xinchuangruanjian";

try {
Class.forName("com.mysql.jdbc.Driver");
conn = DriverManager.getConnection(url, "root", "root");

} catch (Exception e) {
e.printStackTrace();
}
return conn;

}

public static Statement CreatStatement(Connection conn) {
try {
stmt = conn.createStatement();
} catch (SQLException e) {
e.printStackTrace();
}

return stmt;
}

public static ResultSet getResultSet(Statement stmt, String sql) {
try {
rs = stmt.executeQuery(sql);
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

return rs;
}

public static void closs(ResultSet rs, Statement stmt, Connection conn) {
if (rs != null && stmt != null && conn != null) {
try {
rs.close();
stmt.close();
conn.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}

}
}
tnjun123456 2011-12-04
  • 打赏
  • 举报
回复
Class.forName(com.mysql.jdbc.Driver);
这个为什么要注释?
还有String url不知道是做什么····
chituozhilu 2011-12-04
  • 打赏
  • 举报
回复
把web.xml位置放正确!还有参数要对应否则参数是无效的啊!
匿名旅途 2011-12-04
  • 打赏
  • 举报
回复
┏━━━━━━━━━━━━━━━━━━┓
报警:提示没有合适的驱动,请楼主检查!
┗━━━━━━━━━━━━━━━━━━┛
chituozhilu 2011-12-04
  • 打赏
  • 举报
回复
你的WEB.xml放错位置了把!兄弟
代号裤子 2011-12-04
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 scrack 的回复:]
// Class.forName(com.mysql.jdbc.Driver);

你为什么要注释
[/Quote]

对啊
卡胖 2011-12-04
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 zhouyusunquan 的回复:]

你先用代码调试,在控制台看看错误究竟在哪里
[/Quote]
在控制台看了没错误
scrack 2011-12-04
  • 打赏
  • 举报
回复
// Class.forName(com.mysql.jdbc.Driver);

你为什么要注释
zhouyusunquan 2011-12-04
  • 打赏
  • 举报
回复
你先用代码调试,在控制台看看错误究竟在哪里

81,122

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧