用java连接mysql为什么连接不上啊?

龙在水中游 2013-11-02 12:06:35
package wyf.fg;
import java.sql.*;
public class queryData {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Connection con=null;
Statement stmt;
ResultSet rs;
String sqlString="select* from student";
String sd;
try{
Class.forName("com.mysql.jdbc.Driver");
con=DriverManager.getConnection("jdbc:mysql://localhost:3306/test","root","123456");
stmt=con.createStatement();
rs=stmt.executeQuery(sqlString);
while(rs.next()){
sd=rs.getString(1);
System.out.println(sd);
}
//System.out.print");
}catch(Exception e){
e.printStackTrace();
}finally{
try{
con.close();
}catch(SQLException e){
e.printStackTrace();
}
}
}
}
不可以截图,就复制了下来,向大家帮帮忙啊,研究了几天了。。用的连接包也没有显示版本。。
...全文
184 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
龙在水中游 2013-11-02
  • 打赏
  • 举报
回复
呵呵,多谢各位了,已经弄明白了,是包导入问题。。
Rotel-刘志东 2013-11-02
  • 打赏
  • 举报
回复
是通过什么方式连接的是jdbc还是odbc驱动是否已经安装。
ACMAIN_CHM 2013-11-02
  • 打赏
  • 举报
回复
有不有安装驱动?
kobe8free 2013-11-02
  • 打赏
  • 举报
回复
至少把下面的编程工具提示的错误信息贴出来吧! mysql-connect的jar文件导入了没!

56,687

社区成员

发帖
与我相关
我的任务
社区描述
MySQL相关内容讨论专区
社区管理员
  • MySQL
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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