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

📄 infobean.java

📁 职员问答管理系统(java).rar
💻 JAVA
字号:
package mypackage;

import java.sql.*;
import java.io.*;
import java.util.*;
import java.lang.*;

public class InfoBean implements Serializable
{
	protected String UserID="";
	protected String Password="";
	protected String Username="";
	protected String Company="";
	protected String Address="";
	protected String Tel="";
	
	private static Connection conn=null;
	private Statement stmt=null;
	private ResultSet rs=null;
	
	
	//建立数据库连接
	public static void getConnection()
	{
		String url="jdbc:odbc:dbWebInfo";

		try
		{
			Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
			conn=DriverManager.getConnection(url,"","");
		}
		catch(ClassNotFoundException e)
		{
			System.err.println("getConnection1:"+e.getMessage());
		}
		catch(SQLException e)
		{
			System.err.println("getConnection2:"+e.getMessage());
		}
	}
	
	
	//关闭连接
	public void closeConnection()
	{
		try
		{
			if(rs!=null)	rs.close();
			if(stmt!=null)	stmt.close();
			if(conn!=null)	conn.close();
		}
		catch(SQLException e)
		{
			System.err.println("closeConnection:"+e.getMessage());
		}
		finally
		{
			rs=null;
			stmt=null;
			conn=null;
		}
	}
		
		
	//执行数据查询操作
	public ResultSet executeQuery(String sql)
	{
		Connection conn_temp=null;
	  	Statement stmt_temp=null;
	  	ResultSet rs_temp=null;
	  	String Replyer=null;	
	  	try
		{
			
			Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
			conn_temp=DriverManager.getConnection("jdbc:odbc:dbWebInfo","","");
			stmt_temp=conn_temp.createStatement();
			rs_temp=stmt_temp.executeQuery(sql);
		
		}
		catch(Exception e)
		{
			System.err.println("executeQuery:"+e.getMessage());
		}
		finally
		{
			
			
				return rs_temp;
				//rs_temp.close();
				//stmt_temp.close();
			//	conn_temp.close();
		
		
		}

	}
		
		
	//更新数据操作
	public boolean executeUpdate(String sql)
	{
		boolean bUpdate=false;
		try
		{
			if(conn==null)
			{
				getConnection();
			}
			if(conn!=null)
			{
				stmt=conn.createStatement();
				int row=stmt.executeUpdate(sql);
				if(row!=0)
				{
					bUpdate=true;
				}
			}
		}
		catch(SQLException e)
		{
			System.err.println("executeUpdate:"+e.getMessage());
		}
		finally
		{
			return bUpdate;
		}
	}
		
		
	//中文转换
	public static String toChinese(String strvalue)
	{
		try
		{
			if(strvalue==null)
			{
				return null;
			}
			else
			{
				strvalue=new String(strvalue.getBytes("ISO8859_1"),"GBK");
				return strvalue;
			}
		}
		catch(Exception e)
		{
			return null;
		}
	}
	/*
	public static void main(String args[]){
		
		InfoBean ifb1=new InfoBean();
		ifb1.getConnection();
		ifb1.closeConnection();	
	
	}*/

}
		
		
			
	
		

⌨️ 快捷键说明

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