MYSQL FOR JDBC DRIVER的安装问题!

loveflea 2003-07-14 12:51:16
MYSQL FOR JDBC DRIVER

1、下载mysql for jdbc driver.
http://www.mysql.com/downloads/download.php?file=Downloads%2FConnector-J%2Fmysql-connector-java-3.0.8-stable.zip&mirror=http%3A%2F%2Fmysql.todayisp.com%2F

MySQL Connector/J is distributed as a .zip or .tar.gz archive containing
the sources and class files as well as a class-file only "binary" .jar
archive named "mysql-connector-java-3.0.7-stable-bin.jar".

2、解压缩下载的文件,如:mysql-connector-java-3.0.8-stable.zip

You will need to use the appropriate gui or command-line utility to un-archive
the distribution (for example, WinZip for the .zip archive, and "tar" for
the .tar.gz archive).

3、mysql for jdbc driver有两种安装发式:

Once you have un-archived the distribution archive,
you can install the driver in one of two ways:

第一种方法:将com和org两个目录下所有文件和目录拷贝到任何地方,比如d:\mysqlforjdbc下
设置classpath=.;d:\mysqlforjdbc;%classpath%

Either copy the "com" and "org" subdirectories and all of their contents
to anywhere you like, and put the directory holding the "com" and "org"
subdirectories in your classpath, or...

第二种方法:将mysql-connector-java-3.0.7-stable-bin.jar拷贝到一个地方,如:d:\mysqlforjdbc下
设置classpath=.;d:\mysqlforjdbc\mysql-connector-java-3.0.7-stable-bin.jar;%classpath%

或直接把mysql-connector-java-3.0.7-stable-bin.jar拷贝到%JAVA_HOME%\jre\lib\ext下
%JAVA_HOME%就是J2SDK的安装目录,如我的为c:\j2sdk就拷贝到c:\j2sdk\jre\lib\ext下

Put mysql-connector-java-3.0.7-stable-bin.jar in your classpath, either by adding the
FULL path to it to your CLASSPATH enviornment variable, or putting it
in $JAVA_HOME/jre/lib/ext.


想请教一个问题:我的j2sdk安装是正常的,很多例子都可以正常执行
但我安装mysql for jdbc driver后,却怎么都连不上,如:
编译正常、执行确有错误 java.sql.SQLException: No suitable driver
请指教,感觉象是 java.sql异常 没有合适的驱动程序

import java.sql.*;

class MysqlTest
{
public static void main(String[] args)
{
String driver="com.mysql.jdbc.Driver";
String url="jdbc:myql://localhost:3306/sunnywest";
String user="root";
String password="12345";
Connection conn = null;
ResultSet rs = null;
Statement stmt = null;
try
{
Class.forName(driver).newInstance();
}
catch(Exception se)
{
System.out.println(se);
}
try
{
conn = DriverManager.getConnection(url,user,password);
stmt = conn.createStatement();
rs = stmt.executeQuery("select * from send");
while (rs.next())
{
System.out.println("" + rs.getInt(1) + "");
System.out.println(":"+"<br>");
}
rs.close();
conn.close();
}
catch(Exception e)
{
System.out.println(e);
}
}
}
...全文
92 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
loveflea 2003-07-14
  • 打赏
  • 举报
回复
这是我的例子:
1、JavaTM 2 SDK, Standard Edition Version 1.4.1 for windows
位置 c:\j2sdk

2、将mysql-connector-java-3.0.8-stable-bin.zip解压缩到了c:\j2sdk\mysql下
也把mysql-connector-java-3.0.8-stable-bin.jar复制到c:\j2sdk\jre\lib\ext下了

3、set classpath=.;c:\j2sdk\mysql;c:\j2sdk\mysql\mysql-connector-java-3.0.8-stable-bin.jar;%classpath%
loveflea 2003-07-14
  • 打赏
  • 举报
回复
MYSQL FOR JDBC DRIVER INSTALLER

1、下载 mysql for jdbc driver.
文件名字是 mysql-connector-java-3.0.8-stable.zip
包含bin和source两种文件,下在地址是
http://www.mysql.com/downloads/download.php?file=Downloads%2FConnector-J%2Fmysql-connector-java-3.0.8-stable.zip&mirror=http%3A%2F%2Fmysql.todayisp.com%2F

2、解压缩下载的文件,比如这个 mysql-connector-java-3.0.8-stable.zip
建议解压缩到 %JAVA_HOME%\mysql 目录下
%JAVA_HOME%是jdk的安装目录。

3、mysql for jdbc driver有两种或三种安装发式:

第一种方法:因为com和org两个目录都在%JAVA_HOME%\mysql下
set classpath=.;%JAVA_HOME%\mysql;%classpath%

第二种方法:因为mysql-connector-java-3.0.8-stable-bin.jar在 %JAVA_HOME%\mysql 目录下
set classpath=.;%JAVA_HOME%\mysql\mysql-connector-java-3.0.8-stable-bin.jar.jar;%classpath%

第三种方法:直接把mysql-connector-java-3.0.8-stable-bin.jar拷贝到%JAVA_HOME%\jre\lib\ext下
%JAVA_HOME%就是J2SDK的安装目录,如我的为c:\j2sdk就拷贝到c:\j2sdk\jre\lib\ext下

谢谢大家,总结一下,感觉自己还是很粗心,呵呵!
mysql's English Document 请参见
mysql-connector-java-3.0.8-stable.zip
中的README,再次谢谢大家。
明天结帖!
loveflea 2003-07-14
  • 打赏
  • 举报
回复
hehe,搞定,谢谢!
accp 2003-07-14
  • 打赏
  • 举报
回复
String url = "jdbc:myql://localhost:3306/sunnywest";
少一个字母~~~~
String url = "jdbc:mysql://localhost:3306/sunnywest";
loveflea 2003-07-14
  • 打赏
  • 举报
回复
说明:
1、JavaTM 2 SDK, Standard Edition Version 1.4.1 for windows
位置 c:\j2sdk

2、将mysql-connector-java-3.0.8-stable-bin.zip解压缩到了c:\j2sdk\mysql下
也把mysql-connector-java-3.0.8-stable-bin.jar复制到c:\j2sdk\jre\lib\ext下了

3、set classpath=.;c:\j2sdk\mysql;c:\j2sdk\mysql\mysql-connector-java-3.0.8-stable-bin.jar;%classpath%
loveflea 2003-07-14
  • 打赏
  • 举报
回复
java.sql.SQLException: No suitable driver
at java.sql.DriverManager.getConnection(DriverManager.java:532)
at java.sql.DriverManager.getConnection(DriverManager.java:171)
at Mysql.main(Mysql.java:15)


import java.sql.*;

class Mysql
{
public static void main(String[] args) {
try {
String driver = "org.gjt.mm.mysql.Driver";
String url = "jdbc:myql://localhost:3306/sunnywest";
String user = "root";
String password = "sunnyday";
Connection conn = null;
ResultSet rs = null;
Statement stmt = null;
Class.forName(driver).newInstance();
conn = DriverManager.getConnection(url, user, password);
stmt = conn.createStatement();
rs = stmt.executeQuery("select * from send");
while (rs.next()) {
System.out.println("" + rs.getInt(1) + "");
System.out.println(":" + "<br>");
}
rs.close();
conn.close();
}
catch (Exception e) {
e.printStackTrace();
}
}

}
loveflea 2003-07-14
  • 打赏
  • 举报
回复
Issue:

"My application throws a SQLException 'No Suitable Driver'".

Resolution:

One of two things are happening. Either the driver is not in
your CLASSPATH (see the "USAGE AND INSTALLATION" section above), or your
URL format is incoorect (once again see "USAGE AND INSTALLATION").



USAGE AND INSTALLATION

MySQL Connector/J is distributed as a .zip or .tar.gz archive containing
the sources and class files as well as a class-file only "binary" .jar
archive named "mysql-connector-java-3.0.7-stable-bin.jar".

You will need to use the appropriate gui or command-line utility to un-archive
the distribution (for example, WinZip for the .zip archive, and "tar" for
the .tar.gz archive).

Once you have un-archived the distribution archive,
you can install the driver in one of two ways:

Either copy the "com" and "org" subdirectories and all of their contents
to anywhere you like, and put the directory holding the "com" and "org"
subdirectories in your classpath, or...

Put mysql-connector-java-3.0.7-stable-bin.jar in your classpath, either by adding the
FULL path to it to your CLASSPATH enviornment variable, or putting it
in $JAVA_HOME/jre/lib/ext.
accp 2003-07-14
  • 打赏
  • 举报
回复
classpath=.;d:\mysqlforjdbc\mysql-connector-java-3.0.7-stable-bin.jar;%classpath%
你有没有设?
public static void main(String[] args) {
try {
String driver = "org.gjt.mm.mysql.Driver";
String url = "jdbc:myql://localhost:3306/sunnywest";
String user = "root";
String password = "12345";
Connection conn = null;
ResultSet rs = null;
Statement stmt = null;
Class.forName(driver).newInstance();
conn = DriverManager.getConnection(url, user, password);
stmt = conn.createStatement();
rs = stmt.executeQuery("select * from send");
while (rs.next()) {
System.out.println("" + rs.getInt(1) + "");
System.out.println(":" + "<br>");
}
rs.close();
conn.close();
}
catch (Exception e) {
e.printStackTrace();
}
}
这个就可以运行
把你的出错信息贴出来~
loveflea 2003-07-14
  • 打赏
  • 举报
回复
谁能提供一个你那里可以运行的代码?for mysql jdbc,thanks!
loveflea 2003-07-14
  • 打赏
  • 举报
回复
JavaTM 2 SDK, Standard Edition
Version 1.4.1 for windows

accp(只有在梦醒的时候才知道自己是做了一个梦)

String driver="com.mysql.jdbc.Driver";
改成
driver="org.gjt.mm.mysql.Driver";

两个都试过都不行!
accp 2003-07-14
  • 打赏
  • 举报
回复
String driver="com.mysql.jdbc.Driver";
改成
driver="org.gjt.mm.mysql.Driver";
forqzy 2003-07-14
  • 打赏
  • 举报
回复
你的ClassPath中有没有包括mysql-connector-java-3.0.7-stable-bin.jar?
还有你用的JDK是1.3还是1.4?

62,615

社区成员

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

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