源碼超
A. 跪求一個小型超市管理系統,用java編寫的,急~ 只要源代碼。。可以發我郵箱
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class Conn {
private static final String driver="com.mysql.jdbc.Driver";
private static final String url="jdbc:mysql://localhost:3306/blog?user=root&password=root";
//獲得資料庫連接
public static Connection getConnection(){
Connection conn = null;
try {
Class.forName(driver);
conn = DriverManager.getConnection(url);
if(conn != null){
System.out.print("成功");
}
} catch (SQLException e) {
e.printStackTrace();
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
return conn;
}
//關閉Resultset
public static void closeResultSet(ResultSet rs)
{
try
{
if(rs != null)
{
rs.close();
}
}catch (SQLException ex)
{
ex.printStackTrace();
}
}
//關閉Statement
public static void closeStatement(Statement st)
{
try
{
if(st != null)
{
st.close();
}
}catch (SQLException ex)
{
ex.printStackTrace();
}
}
//關閉Connection
public static void closeConnection(Connection conn)
{
try
{
if(conn != null)
{
conn.close();
}
}catch (SQLException ex)
{
ex.printStackTrace();
}
}
//測試資料庫連接是否成功
public static void main(String[] args) {
Conn.getConnection();
}
}