connect.java

来自「java编写的电子商务网站源码,做的一个电脑直销网站,后台数据库使用的是MS S」· Java 代码 · 共 56 行

JAVA
56
字号
package beans;

import java.sql.*;
import javax.servlet.jsp.*;

public class Connect{
	private String table = null;
	private ResultSet rs = null;	
	private String driver = "com.microsoft.jdbc.sqlserver.SQLServerDriver";
	private String url = "jdbc:microsoft:sqlserver://localhost:1433";
	private String user = "nick";
	private String password = "123";
	private Connection c = null;
	private PreparedStatement ps = null;	
	private int count = 0;	
	
	public Connect() throws JspException{
		try{
			Class.forName(driver);						
		}	
		catch(ClassNotFoundException cnfe){throw new JspException(cnfe);}
	}
	public String getTable(){
		return this.table;
	}
	public void setTable(String table){
		this.table = table;
	}	
	public ResultSet getResult(){			
		return this.rs;
	}
	public void setResult(ResultSet rs){
		this.rs = rs;
	}
	public int getCount(){
		return this.count;
	}
	public void setCount(){
		this.count = count;
	}
	public void query() throws JspException{
		try{
			c = DriverManager.getConnection(url,user,password);		
			ps = c.prepareStatement("select * from "+table,ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_UPDATABLE);
			rs = ps.executeQuery();						
			if(rs!=null){
				rs.last();											
				count = rs.getInt(1);				
			}
			else 
				count = 0;
		}
		catch(SQLException sqle){throw new JspException(sqle);}				
	}
}

⌨️ 快捷键说明

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