package com.szu.osgi;
import java.sql.*;
public class DatabaseBundle {
protected static Connection conn = null;
static String driver = "com.mysql.jdbc.Driver";
static String dbUrl = "jdbc:mysql://localhost:3306/test";
static String dbUser = "root";
static String dbPassword = "root";
public static Statement stmt = null;
public static void openConnection() {
try {
Class.forName(driver);
conn = DriverManager.getConnection(dbUrl, dbUser, dbPassword);
} catch (Exception ex) {
System.err.println("connection failed!");
ex.printStackTrace();
return;
}
}
public static void closeConnection()
{
if(conn != null) {
try {
conn.close();
} catch (Exception ex) {
return;
}
}
}
public static void updateUserTable(String pass, String fullname)
{
try {
String sql = "INSERT INTO user(username, password) VALUES ('admin','admin')";
System.out.println("当前插入SQL语句:"+sql);
Statement stmt = conn.createStatement();
stmt.executeUpdate(sql);
} catch (Exception ex) {
System.out.println("SQL 出错!"+ex.getMessage());
return;
}
}
}