连接mysql的url写法

连接mysql的url写法,第1张

这样:

jdbc:mysql://<hostname>[<:3306>]/<dbname>

jdbc:mysql://localhost:3306/db_librarySys

Connection conn = DriverManager.getConnection ("jdbc:mysql://localhost:3306/db_librarySys?user=root&password=1234")

Connection conn = DriverManager.getConnection ("jdbc:mysql://localhost:3306/db_librarySys", "root", "1234")

扩展资料:

注意事项

URL=协议名+子协议名+数据源名。

1、协议名总是“jdbc”。

2、子协议名由JDBC驱动程序的编写者决定。

3、数据源名也可能包含用户与口令等信息;这些信息也可单独提供。

URL:jdbc:oracle:thin:@machine_name:port:dbname

注:machine_name:数据库所在的机器的名称;

port:端口号,默认是1521

Class.forName("oracle.jdbc.driver.OracleDriver").newInstance()

String url="jdbc:oracle:thin:@localhost:1521:orcl"

//orcl为数据库的SID

String user="test"

String password="test"

Connection conn= DriverManager.getConnection(url,user,password)

注意:Oracle的URL有两种写法:

1、jdbc:oracle:thin:@localhost:1521:databaseName   常用 *** 作sql的工具:sqlDeveloper.exe,还可以用其他数据库,如mysql等

2、jdbc:oracle:oci:@localhost:1521:databaseName    用来 *** 作SQL的工具只能用:PL/SQL Developer;数据库集群时候常用此连接,比上面那个多点功能,性能好点。

mysql5.0

driver-class-name: com.mysql.jdbc.Driver

url: jdbc:mysql://localhost:3306/testspringboot?useSSL=false

mysql8.0

driver-class-name: com.mysql.cj.jdbc.Driver

url: jdbc:mysql://localhost:3306/testspringboot?useSSL=false&serverTimezone=UTC

1,很多人还是很穷的,没有技术一般都是在本地学习测试,那么我就从本地测试环境开始说,这里以wampserver为例:我的安装在D盘符,打开地址如下:D:\wamp\bin\mysql\mysql5.5.20\bin;

2,打开mysql.exe文件,输入密码回车确定显示如下页面证明你登录成功了;

3,在mysql后面输入show global variables like 'port'别写错了,切记别忘记写英文状态下的分号;

4,如果大家怕打错了想复制我这个代码,复制后不要去CTRl+V粘贴,那是不对的,要在会话窗口,也就是这个黑色框内,右键-粘贴。


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/8656520.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-19
下一篇 2023-04-19

发表评论

登录后才能评论

评论列表(0条)

保存