java.sql.SQLException: No suitable driver 求解,在线等...
1.mysql-connector-java-5.1.13-bin.jar路径添写入classpath2.mysql-connector-java-5.1.13-bin....
1.mysql-connector-java-5.1.13-bin.jar路径添写入classpath
2.mysql-connector-java-5.1.13-bin.jar复制粘贴到jdk\jre\lib\ext下
以上两种方法都尝试了,解决不了,而且我已看贴无数,折腾半天了
版本:jdk1.5.0_06 , MySQL 5.0 ,mysql-connector-java-5.1.13 ,JCreator4.5
以下是源码:
import java.sql.*;
public class DisplayAuthors
{ static final String DATABASE_URL = "jdbc:mysql://localhost/books";
public static void main( String args[] )
{
Connection connection = null;
Statement statement = null;
ResultSet resultSet = null;
try
{
// establish connection to database
connection = DriverManager.getConnection(
DATABASE_URL, "javafp", "javafp" );
statement = connection.createStatement();
resultSet = statement.executeQuery(
"SELECT * FROM authors" );
ResultSetMetaData metaData = resultSet.getMetaData();
int numberOfColumns = metaData.getColumnCount();
for ( int i = 1; i <= numberOfColumns; i++ )
System.out.printf( "%-8s\t", metaData.getColumnName( i ) );
System.out.println();
while ( resultSet.next() )
{
for ( int i = 1; i <= numberOfColumns; i++ )
System.out.printf( "%-8s\t", resultSet.getObject( i ) );
System.out.println();
}
}
catch ( SQLException sqlException )
{
sqlException.printStackTrace();
}
finally
{
try
{
resultSet.close();
statement.close();
connection.close();
} // end try
catch ( Exception exception )
{
exception.printStackTrace();
} // end catch
} // end finally
} // end main
} // end class DisplayAuthors
error:
java.sql.SQLException: No suitable driver
at java.sql.DriverManager.getConnection(DriverManager.java:545)
at java.sql.DriverManager.getConnection(DriverManager.java:171)
at DisplayAuthors.main(DisplayAuthors.java:22)
java.lang.NullPointerException
at DisplayAuthors.main(DisplayAuthors.java:56)
我写了这句话Class.forName("com.mysql.jdbc.Driver") 运行时提示
java.lang.ClassNotFoundException: com.mysql.jdbc.Driver,这怎么办啊? 展开
2.mysql-connector-java-5.1.13-bin.jar复制粘贴到jdk\jre\lib\ext下
以上两种方法都尝试了,解决不了,而且我已看贴无数,折腾半天了
版本:jdk1.5.0_06 , MySQL 5.0 ,mysql-connector-java-5.1.13 ,JCreator4.5
以下是源码:
import java.sql.*;
public class DisplayAuthors
{ static final String DATABASE_URL = "jdbc:mysql://localhost/books";
public static void main( String args[] )
{
Connection connection = null;
Statement statement = null;
ResultSet resultSet = null;
try
{
// establish connection to database
connection = DriverManager.getConnection(
DATABASE_URL, "javafp", "javafp" );
statement = connection.createStatement();
resultSet = statement.executeQuery(
"SELECT * FROM authors" );
ResultSetMetaData metaData = resultSet.getMetaData();
int numberOfColumns = metaData.getColumnCount();
for ( int i = 1; i <= numberOfColumns; i++ )
System.out.printf( "%-8s\t", metaData.getColumnName( i ) );
System.out.println();
while ( resultSet.next() )
{
for ( int i = 1; i <= numberOfColumns; i++ )
System.out.printf( "%-8s\t", resultSet.getObject( i ) );
System.out.println();
}
}
catch ( SQLException sqlException )
{
sqlException.printStackTrace();
}
finally
{
try
{
resultSet.close();
statement.close();
connection.close();
} // end try
catch ( Exception exception )
{
exception.printStackTrace();
} // end catch
} // end finally
} // end main
} // end class DisplayAuthors
error:
java.sql.SQLException: No suitable driver
at java.sql.DriverManager.getConnection(DriverManager.java:545)
at java.sql.DriverManager.getConnection(DriverManager.java:171)
at DisplayAuthors.main(DisplayAuthors.java:22)
java.lang.NullPointerException
at DisplayAuthors.main(DisplayAuthors.java:56)
我写了这句话Class.forName("com.mysql.jdbc.Driver") 运行时提示
java.lang.ClassNotFoundException: com.mysql.jdbc.Driver,这怎么办啊? 展开
3个回答
展开全部
你首先需要使用Class.forName("com.mysql.jdbc.Driver");
加载驱动类,才能获得连接.
加载驱动类,才能获得连接.
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
1.你没有指定端口,如:jdbc:mysql://localhost:3306/books。
2.你没有将驱动程序读入内存,如:Class.forName("com.mysql.jdbc.Driver")。
2.你没有将驱动程序读入内存,如:Class.forName("com.mysql.jdbc.Driver")。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询