java jdbc连接mysql报错:No suitable driver found for jdbc
源代码importjava.lang.*;importjava.sql.*;publicclassshujuku{publicstaticvoidmain(String[...
源代码
import java.lang.*;
import java.sql.*;
public class shujuku
{
public static void main(String[] args)
{
Connection con;
Statement sql;
ResultSet rs;
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}
catch(ClassNotFoundException e)
{
System.out.println(e);
}
try
{
String url = "jdbc:odbc:star";
con = DriverManager.getConnection(url);
sql = con.createStatement();
rs = sql.executeQuery("SELECT * FROM employee WHERE salary>1900");
while(rs.next())
{
String number = rs.getString(1);
String name = rs.getString(2);
Date date = rs.getDate("birthday");
double salary = rs.getDouble("salary");
System.out.printf("% - 4s",number);
System.out.printf("% - 6s",name);
System.out.printf("% - 15s",date.toString());
System.out.printf("% - 6s\n",salary);
}
con.close();
}
catch(SQLException e)
{
System.out.println(e);
}
}
}
已经查过好多解决方法了,mysql-connector-java-5.0.8放在了E:\软件\Java\jre8\lib\ext文件夹下
CLASSPATH 写的是E:\软件\Java\jre8\lib\rt.jar;E:\软件\Java\jre8\lib\ext\mysql-connector-java-5.0.8.jar
数据源star创建了,可是就是链接不上,问题是什么啊?? 展开
import java.lang.*;
import java.sql.*;
public class shujuku
{
public static void main(String[] args)
{
Connection con;
Statement sql;
ResultSet rs;
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}
catch(ClassNotFoundException e)
{
System.out.println(e);
}
try
{
String url = "jdbc:odbc:star";
con = DriverManager.getConnection(url);
sql = con.createStatement();
rs = sql.executeQuery("SELECT * FROM employee WHERE salary>1900");
while(rs.next())
{
String number = rs.getString(1);
String name = rs.getString(2);
Date date = rs.getDate("birthday");
double salary = rs.getDouble("salary");
System.out.printf("% - 4s",number);
System.out.printf("% - 6s",name);
System.out.printf("% - 15s",date.toString());
System.out.printf("% - 6s\n",salary);
}
con.close();
}
catch(SQLException e)
{
System.out.println(e);
}
}
}
已经查过好多解决方法了,mysql-connector-java-5.0.8放在了E:\软件\Java\jre8\lib\ext文件夹下
CLASSPATH 写的是E:\软件\Java\jre8\lib\rt.jar;E:\软件\Java\jre8\lib\ext\mysql-connector-java-5.0.8.jar
数据源star创建了,可是就是链接不上,问题是什么啊?? 展开
展开全部
mysql-connector-java-5.0.8.jar是放到项目的lib文件夹里,,还要buildpath一下
==========-==========-======
我给你我之前eclipse连mysql数据库的例子JDBC的==
当时我的数据库名是mysql0120登陆名root密码root2==
代码已上传,你参考下==
追问
String url = "jdbc:mysql://localhost:3306/mysql0120"这个是什么意思啊?如果我用你发的这个的话是不是需要自己建立一个mysql0120的数据库?是用access编辑么?还有路径是哪里呢?感谢..
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询