initial.java

来自「用最近的dojo1.2.1制作前端的ajax购书网站」· Java 代码 · 共 76 行

JAVA
76
字号
package server.database;
import java.util.*;
import java.sql.*;

/**
 * @author user
 *
 * 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 Initial {
	private DBData data=new DBData();
	private String url=data.getURL();
	private String name=DBData.getNAME();
	private String password=DBData.getPASSWORD();
	private String classname=DBData.getCLASSNAME();
	private String DATABASE=data.getDATABASE();
	
	
	
	private Connection conn=null;
	Statement stat=null;
	ResultSet rs=null;
	String setDATABASE(String database)
	{
		DATABASE=database;
		return DATABASE;
	}
	private void getConnection()
	throws SQLException,InstantiationException,IllegalAccessException,ClassNotFoundException
	{	
		
		Class.forName(classname).newInstance();
		//Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
		conn=DriverManager.getConnection(url,name,password);
	}
	Statement getStatement()
	throws SQLException,InstantiationException,IllegalAccessException,ClassNotFoundException
	{	
		if(conn==null)
		{
			getConnection();
		}
	
		stat=conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
		return stat;
		

	}
	
	void closeStatement()
	throws SQLException,InstantiationException,IllegalAccessException,ClassNotFoundException
	{
		if(stat!=null)
		stat.close();
		
	}
	void closeResultSet()
	throws SQLException,InstantiationException,IllegalAccessException,ClassNotFoundException
	{
		if(rs!=null)
		rs.close();
		
	}
	void closeConnection()
	throws SQLException,InstantiationException,IllegalAccessException,ClassNotFoundException
	{
		if(conn!=null)
		conn.close();
		
	}
	
}

⌨️ 快捷键说明

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