myeclipse不识别Class.forName("com.mysql.jdbc.Driver") myeclipse不识别Class.forName("com.mysql.jdbc.Driver")问题是有个javaweb项目用到jbdc可以使用自学很苦逼,忘大神给解决一下 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 你能把代码发全么?你能说下 你放好mysql的驱动jar包了么 Class.forName("org.gjt.mm.mysql.Driver").newInstance(); public class DBUtil { try { Class.forName("com.mysql.jdbc.Dirver"); } catch (ClassNotFoundException e) {} public static Connection getCon()throws Exception{ String url = "jdbc:mysql://localhost:3306/search?useUnicode=true&characterEncoding=utf8"; Connection con = DriverManager.getConnection(url,"root","root"); return con; }} 感觉就是 驱动jar 没有 导入 楼主 导入jar报了吗百分之八十就这个问题!!! Class.forName("com.mysql.jdbc.Dirver"); 这句话为啥不识别 代码在楼上 我不是很懂但我这3个jar包都导入了 这些jar要放到WEB-INF下的那个lib文件下 擦try {Class.forName("com.mysql.jdbc.Dirver");} catch (ClassNotFoundException e) {}你就直接放类里面了 都没放方法里 可以这么放么 public class JdbcUtil { private static final String url = "jdbc:mysql://localhost:3306/dbdemo?useUnicode=true&characterEncoding=UTF-8"; private static final String user = "root"; private static final String password = "sa"; private static ThreadLocal<Connection> connectionContainer = new ThreadLocal<Connection>(); /** * 注册 * * @throws ClassNotFoundException * @throws SQLException */ public static Connection register() { Connection connection = connectionContainer.get(); try { if (connection == null) { try { Class.forName("com.mysql.jdbc.Driver"); } catch (ClassNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } connection = DriverManager.getConnection(url, user, password); } connectionContainer.set(connection); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } return connection; } public static void freeResource(Statement statement, ResultSet rs) { try { if (rs != null) { rs.close(); } if (statement != null) { statement.close(); } Connection connection = connectionContainer.get(); if (connection != null) { connection.close(); } } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } finally { connectionContainer.remove(); } }} 楼主可以选中导入的那三个jar包然后右键 build path 这样就可以了!!!!! mysql 存储过程 传表名 让所有的jsp都检测同一个session? 后台多条件多选查询统计 怎样让在页面里显示(<IMG src="D:\Backup\a.jpg">)文字变为图片? 在线考试系统 关于FCKeditor保存信息取出至FCKeditor中的问题? 数据库小问题 如何从数据库中读出BLOB数据?(100分) 使用java bean与否到底有什么区别? 入门问题 求教:servlet无法将表单获取的数据插入数据库 一个Javascript的问题
try {
Class.forName("com.mysql.jdbc.Dirver");
} catch (ClassNotFoundException e) {}
public static Connection getCon()throws Exception{
String url = "jdbc:mysql://localhost:3306/search?useUnicode=true&characterEncoding=utf8";
Connection con = DriverManager.getConnection(url,"root","root");
return con;
}
}
我不是很懂但我这3个jar包都导入了
try {
Class.forName("com.mysql.jdbc.Dirver");
} catch (ClassNotFoundException e) {}
你就直接放类里面了 都没放方法里 可以这么放么
private static final String user = "root";
private static final String password = "sa"; private static ThreadLocal<Connection> connectionContainer = new ThreadLocal<Connection>(); /**
* 注册
*
* @throws ClassNotFoundException
* @throws SQLException
*/
public static Connection register() {
Connection connection = connectionContainer.get();
try {
if (connection == null) {
try {
Class.forName("com.mysql.jdbc.Driver");
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
connection = DriverManager.getConnection(url, user, password);
}
connectionContainer.set(connection);
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return connection;
} public static void freeResource(Statement statement, ResultSet rs) {
try {
if (rs != null) {
rs.close();
}
if (statement != null) {
statement.close();
}
Connection connection = connectionContainer.get();
if (connection != null) {
connection.close();
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
connectionContainer.remove();
}
}
}
然后右键 build path
这样就可以了!!!!!