⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 databaseconnection.java

📁 一个简易的网上书店(jsp+sqlservler+struts)。
💻 JAVA
字号:
package com.webshop.db;
import java.sql.*;
import javax.naming.*;
import javax.sql.DataSource;
/**
 * @author w
 *
 * To change this generated comment edit the template variable "typecomment":
 * Window>Preferences>Java>Templates.
 * To enable and disable the creation of type comments go to
 * Window>Preferences>Java>Code Generation.
 */

public class DatabaseConnection {
	public static Connection getConnection() throws SQLException,NamingException
	{
		try
		{
			
			Context initCtx = new javax.naming.InitialContext(); 
            Context envCtx = (Context) initCtx.lookup("java:comp/env"); 
            DataSource ds = (DataSource)envCtx.lookup("jdbc/eshop"); 
  
			return ds.getConnection();
		}
		catch(SQLException e)
		{
			throw e;
		}
		catch(NamingException e)
		{
			throw e;
		}
		
	}

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -