这样:
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;数据库集群时候常用此连接,比上面那个多点功能,性能好点。
查询MySQL数据库所有表名的SQL命令:
show tables
查询MySQL数据库有表结构的SQL命令:
show create table tblName
例如:show create table students
CREATE TABLE `students` (
`sid` char(10) NOT NULL,
`sname` varchar(50) NOT NULL,
`sex` char(1) NOT NULL,
`dob` date NOT NULL,
`phone` varchar(30) DEFAULT NULL,
PRIMARY KEY (`sid`),
KEY `index_tbl1_url` (`phone`(20))
) ENGINE=InnoDB DEFAULT CHARSET=gb2312
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)