Home > Database > Mysql Tutorial > jdbc- 连接mysql老是出现连接失败?

jdbc- 连接mysql老是出现连接失败?

WBOY
Release: 2016-06-06 09:45:41
Original
1318 people have browsed it

mysqljdbcjava

新建的java工程,测试代码如下,已经把驱动程序拷贝到JRE system liabrary 中
package com.test.tao;

import java.sql.*;
public class Test {
public static void main(String args[])
{
try{
Class.forName("com.mysql.jdbc.Driver");
System.out.print("加载数据库成功");
String str="jdbc:mysql://localhost:3306/test?"+"user=root&password=123456";
Connection conn=DriverManager.getConnection(str);

System.out.print("连接成功");
}
catch (Exception e)
{System.out.print("连接失败");}
}

}

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template