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

📄 datamysqconnection.java

📁 这是一个JSP网站程序
💻 JAVA
字号:
package com.yibo.yiqu.db;

import java.sql.*;
import javax.naming.*;
import javax.sql.DataSource;
/**
 * @author liuzhaofeng
 *
 * Window>Preferences>Java>Code Generation.
 */
public class DataMYSQConnection{
	
/*	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/template"); 
  
			return ds.getConnection();
		}
		catch(SQLException e)
		{
			throw e;
		}
		catch(NamingException e)
		{
			throw e;
		}
	}	
	//connect by mssql
     public static Connection getConnection() throws Exception
	{
		try
		{
			 Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance();			 
  
			return DriverManager.getConnection("jdbc:microsoft:sqlserver://127.0.0.1:1433;DatabaseName=bing","sa","851200");
		}
		catch(Exception e2)
		{
			throw e2;
		}
	}
	*/
	//connect by mysql --->baseuser_info
public static Connection getConnectionbase() throws Exception
	{
		try
		{
		    Class.forName("com.mysql.jdbc.Driver").newInstance();			 
  
			return DriverManager.getConnection("jdbc:mysql://localhost:3306/entrysvr?useUnicode=true&characterEncoding=gbk","root","yzhlzh");
		}
		catch(Exception e2)
		{
			throw e2;
		}
	}	
	//connect by mysql ---->game 222.141.219.149
public static Connection getConnection() throws Exception
	{
		try
		{
		    Class.forName("com.mysql.jdbc.Driver").newInstance();			 
  
			return DriverManager.getConnection("jdbc:mysql://222.141.219.149:3306/entrysvr","root","yzhlzh");
		}
		catch(Exception e2)
		{
			throw e2;
		}
	}
}

⌨️ 快捷键说明

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