jsp如何连接mysql??急急急~!

来源:百度知道 编辑:UC知道 时间:2024/06/03 04:59:21
这是我连接用的

代码
======================================
<%@ page contentType="text/html; charset=gb2312" %>

<%@ page language="java" %>

<%@ page import="com.mysql.jdbc.Driver" %>

<%@ page import="java.sql.*" %>

<%

//驱动程序名

String driverName="com.mysql.jdbc.Driver";

//数据库用户名

String userName="cl41";

//密码

String userPasswd="123456";

//数据库名

String dbName="db";

//表名

String tableName="dbtest";

//联结字符串

String url="jdbc:mysql://localhost/"+dbName+"?user="+userName+"&password="+userPasswd;

Class.forName("com.mysql.jdbc.Driver").newInstance();

Connection connection=DriverManager.getConnection(url);

State

Generated servlet error:
F:\tomcat\Tomcat 5.0\work\Catalina\localhost\_\org\apache\jsp\_1_jsp.java:6: 软件包 com.mysql.jdbc 不存在
import com.mysql.jdbc.Driver;

去系在这个包然后放到库里面
另外
String url="jdbc:mysql://localhost/"+dbName+"?
需要加上mysql的端口号

1.tomacat配置有问题
2.java配置