package cn;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
import com.mysql.jdbc.Driver;
public class jdbc {
public static void main(String[] args) throws Exception {
Class.forName("com.mysql.jdbc.Driver");
System.out.println("数据库驱动加载成功");
Connection conn = DriverManager.getConnection("jdbc:mysql//localhost:3306/girls", "root", "123456");
System.out.println("创建连接成功");
String sql="update admin set username= 9999 where id=1";
Statement stmt = conn.createStatement();
int count = stmt.executeUpdate(sql);
System.out.println( count );
stmt.close();
conn.close();
}
}
为什么我用idea连接mysql会一直报异常,我已经驱动包导进去了
- 写回答
- 好问题 0 提建议
- 追加酬金
- 关注问题
- 邀请回答
-
5条回答 默认 最新
- CSDN专家-sinJack 2021-09-07 20:59关注
url写错了。mysql后面少写了冒号:
package cn; import java.sql.Connection; import java.sql.DriverManager; import java.sql.SQLException; import java.sql.Statement; import com.mysql.jdbc.Driver; public class jdbc { public static void main(String[] args) throws Exception { Class.forName("com.mysql.jdbc.Driver"); System.out.println("数据库驱动加载成功"); Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/girls", "root", "123456"); System.out.println("创建连接成功"); String sql="update admin set username= 9999 where id=1"; Statement stmt = conn.createStatement(); int count = stmt.executeUpdate(sql); System.out.println( count ); stmt.close(); conn.close(); } }
解决 无用评论 打赏 举报
悬赏问题
- ¥15 陆空双模式无人机飞控设置
- ¥15 sentaurus lithography
- ¥100 求抖音ck号 或者提ck教程
- ¥15 关于#linux#的问题:子进程1等待子进程A、B退出后退出(语言-c语言)
- ¥20 web页面如何打开Outlook 365的全球离线通讯簿功能
- ¥15 io.jsonwebtoken.security.Keys
- ¥15 急,ubuntu安装后no caching mode page found等
- ¥15 联想交换机NE2580O/NE1064TO安装SONIC
- ¥15 防火墙的混合模式配置
- ¥15 Ubuntu不小心注销了要怎么恢复啊