快捷导航

as连接mysql异常

/*这是我写的一个java类,照着网上敲的代码,代码内容也理解,用as连接mysql在学习当中,希望大神指点一下,感激不尽*/publicclassrenWu{publicstaticvoidmain(String[]args){Connectionconn=null;Stringdriver="com.mysql.jdbc.Driver";//MySQL驱动Stringurl="jdbc:mysql://localhost:3306/TASK";//MYSQL数据库连接UrlStringuser="root";//用户名Stringpassword="123456";try{Class.forName(driver);try{conn=DriverManager.getConnection(url,user,password);if(conn!=null){System.out.println("成功");}else{System.out.println("失败");}}catch(SQLExceptione){e.printStackTrace();}}catch(ClassNotFoundExceptione){e.printStackTrace();}}}

免责声明:本内容仅代表回答者见解不代表本站观点,请谨慎对待。

版权声明:作者保留权利,不代表本站立场。

回复

使用道具 举报

参与会员2

选中jar包,右键选择“Add As Library”
回复

使用道具 举报

有mysql对应的jar吗
回复

使用道具 举报

可能感兴趣的问答

发新帖
  • 微信访问
  • 手机APP