MYSQL FOR JDBC DRIVER的安装问题!
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);
}
}
}