请教一下关于通过JDBC连接MYSQL的问题 http://tech.ccidnet.com/pub/article/c1110_a173155_p1.html 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 代码没有错误。楼主可以直接通过application来测试一下能不能连接到数据库。如果也不行,那应该是mm.mysql-2.0.4-bin.jar包有问题。 org.gjt.mm.mysql.Driver它用的是Connect/J 3.0以上的版本的,以前的不是这个是另外一个。 以前的是com.mysql.jdbc.Driver.是这个,楼主把Driver换成这个试试。 我写的一个数据库连接,给你参考一下,默认是连接mysql,serverType等于sqlserver的时候连接的是sqlserver: public final Connection myConn(String serverType) throws SQLException, InstantiationException, IllegalAccessException, ClassNotFoundException { Connection conn = null; String driver = new String(); String connString = new String(); driver = "com.mysql.jdbc.Driver"; connString = "jdbc:mysql://localhost/dreamsite?user=root&password="; if (serverType.equals("sqlserver")) { driver = "com.microsoft.jdbc.sqlserver.SQLServerDriver"; } Class.forName(driver).newInstance(); conn = DriverManager .getConnection("jdbc:mysql://localhost/dreamsite?user=root&password="); if (serverType.equals("sqlserver")) { connString = "jdbc:microsoft:sqlserver://192.168.2.100:1433;databaseName=video"; String databaseName = "sa"; String password = "123456"; conn = DriverManager.getConnection(connString, databaseName, password); } return conn; } 用mysql自己的最新驱动就可以了 关于tomcat5.5的问题连接池问题 XML十万火急 jxl的应用,如何向一个已经存在的excel表中添加一个sheet 关于保存网页为word的问题 一个页面用struts实现始终不知道该如何下手 基于J2EE的数据访问 如何用Java生成这样的XML文件???其中有一句我加不进去 基于J2EE的中间件和WEB SERVICES,我选择哪个?请指教 javamail收信时怎么处理中文名的附件?在线 初学,如果处理ajax和servlet关系 jsp 连 sql server 的问题 请问org.apache.commons.net.tftp包在哪下载?
public final Connection myConn(String serverType) throws SQLException,
InstantiationException, IllegalAccessException,
ClassNotFoundException {
Connection conn = null;
String driver = new String();
String connString = new String();
driver = "com.mysql.jdbc.Driver";
connString = "jdbc:mysql://localhost/dreamsite?user=root&password=";
if (serverType.equals("sqlserver")) {
driver = "com.microsoft.jdbc.sqlserver.SQLServerDriver";
} Class.forName(driver).newInstance();
conn = DriverManager
.getConnection("jdbc:mysql://localhost/dreamsite?user=root&password="); if (serverType.equals("sqlserver")) {
connString = "jdbc:microsoft:sqlserver://192.168.2.100:1433;databaseName=video";
String databaseName = "sa";
String password = "123456"; conn = DriverManager.getConnection(connString, databaseName,
password); }
return conn;
}