一个小型的购物商店
源代码在线查看: dbconnection.java
/*
* DBConnection.java
*
* Created on 2006年9月23日, 下午5:48
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/
package com.shopping.resource;
import java.sql.*;
//import java.util.*;
//import javax.sql.DataSource;
//import javax.naming.*;
/**
*
* @author 曹昊
*/
public class DBConnection {
// private static DataSource ds = null;
// static{
// try {
// //连接JNDI服务器
// Context context = new InitialContext();
// //读取数据源
// ds = (DataSource)context.lookup("java:comp/env/"+"jdbc/localMySQL");
// } catch (NamingException ex) {
// ex.printStackTrace();
// }
// }
public static Connection getConnection(){
Connection conn = null;
try {
Class.forName("com.mysql.jdbc.Driver");
conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/shoppingcart","root","1234");
// conn = ds.getConnection();
} catch (Exception ex) {
ex.printStackTrace();
}
return conn;
}
}