[求助]mysql驱动程序
测试数据库显示no suitable driver怎么加载mysql驱动程序?
import java.sql.*;
import java.io.*;
import java.util.*;
public class TestDb
{
public static void main(String args[])
{
try
{
runTest();
}
catch(SQLException ex)
{
while(ex!=null)
{
ex.printStackTrace();
ex=ex.getNextException();
}
}
catch(IOException ex)
{
ex.printStackTrace();
}
}
public static void runTest()
throws SQLException,IOException
{
String drivers="com.mysql.jdbc.Driver";
String url="jdbc:mysql://localhost:3360/myfirst";
String username="root";
String password="iloveyy";
try
{
Class.forName("com.mysql.jdbc.Driver");
}
catch(ClassNotFoundException e){}
Connection conn=DriverManager.getConnection(url,username,password);
try
{
Statement stat=conn.createStatement();
stat.execute("CREATE TABLE Greetings (Message CHAR(20))");
stat.execute("INSERT INTO Greetings VALUES ('HELLO WORLD')");
ResultSet result=stat.executeQuery("SELECT * FROM Greetings");
result.next();
System.out.println(result.getString(1));
}
finally
{
conn.close();
}
}
}