根据zol问答官方资料显示,mysqld.exe是系统安装了mysql之后才会有的进程,架设服务器才需要的,不需要的时候可以关闭。
MySQLforWindows设置默认开机自动启动,一定程度上将导致电脑开机时,系统需要花更多的时间和精力。
//建议你还是装个 mysql 吧~~ ,小而精悍.维护也好,给个连接mysql的例子先~~import java.io.File
import java.io.FileInputStream
import java.net.URI
import java.sql.*
import java.util.PropertyResourceBundle
public class MySqlConnector {
/*
* 先在该class文件目录下新建一个dbCon.ini
* 如:eclipse 则 your project/bin/dbCon.ini
* 内容 如下:
* password=你的数据库用户密码
* database=要连接的数据库名称
*/
private static final String CON_NAME = "userName"
private static final String CON_PASS = "password"
private static final String CON_DNAME = "databaseName"
private Connection connection = null
private MySqlConnector() {
}
public static MySqlConnector getInstance() {
return new MySqlConnector()
}
private boolean dataInit() {
boolean isOK = false
String userName = null
String password = null
String databaseName = null
PropertyResourceBundle rBoundle = null
try {
String conPath = MySqlConnector.class.getResource("/").toString() + "/dbCon.ini"
URI uri = new URI(conPath)
File file = new File(uri)
rBoundle = new PropertyResourceBundle(new FileInputStream(file))
userName = rBoundle.getString(MySqlConnector.CON_NAME)
password = rBoundle.getString(MySqlConnector.CON_PASS)
databaseName = rBoundle.getString(MySqlConnector.CON_DNAME)
String url
url = "jdbc:mysql://localhost/" + databaseName + "?user="
+ userName + "&password=" + password
System.out.println(url)
Class.forName("com.mysql.jdbc.Driver")
connection = DriverManager.getConnection(url)
isOK = true
} catch (Exception e) {
e.printStackTrace()
isOK = false
}
return isOK
}
public Connection getConnection() {
if (dataInit()) {
return connection
} else {
return null
}
}
public static void main(String [] args){
MySqlConnector.getInstance().getConnection()
}
public void close() {
if (connection != null) {
try {
connection.close()
} catch (SQLException e) {
e.printStackTrace()
}
}
}
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)