在MySQL中添加数据库
2007-12-23 12:35:32 来源:WEB开发网核心提示:import java.sql.Connection;import java.sql.DriverManager;import java.sql.SQLException;import java.sql.Statement;public class MainClass {public static void main(
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
public class MainClass {
public static void main(String[] args) {
Connection connection = null;
Statement statement = null;
try {
Class.forName("org.gjt.mm.MySQL.Driver").newInstance();
String url = "jdbc:mysql://localhost/mysql";
connection = DriverManager.getConnection(url, "username", "passWord");
statement = connection.createStatement();
String hrappSQL = "CREATE DATABASE hrapp";
statement.executeUpdate(hrappSQL);
} catch (Exception e) {
e.PRintStackTrace();
} finally {
if (statement != null) {
try {
statement.close();
} catch (SQLException e) {
}
}
if (connection != null) {
try {
connection.close();
} catch (SQLException e) {
}
}
}
}
}
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
public class MainClass {
public static void main(String[] args) {
Connection connection = null;
Statement statement = null;
try {
Class.forName("org.gjt.mm.MySQL.Driver").newInstance();
String url = "jdbc:mysql://localhost/mysql";
connection = DriverManager.getConnection(url, "username", "passWord");
statement = connection.createStatement();
String hrappSQL = "CREATE DATABASE hrapp";
statement.executeUpdate(hrappSQL);
} catch (Exception e) {
e.PRintStackTrace();
} finally {
if (statement != null) {
try {
statement.close();
} catch (SQLException e) {
}
}
if (connection != null) {
try {
connection.close();
} catch (SQLException e) {
}
}
}
}
}
(出处:http://www.cncms.com)
[]
更多精彩
赞助商链接