condb.java

来自「在线投票系统代码」· Java 代码 · 共 50 行

JAVA
50
字号
package beans;

import java.sql.*;

public class Condb{
	String dbname="jdbc:mysql://127.0.0.1:3306/music";
	ResultSet rs=null;
	Connection con=null;
	Statement stmt=null;
	public Condb(){
		try{
				Class.forName("org.gjt.mm.mysql.Driver");
		}catch(ClassNotFoundException e1){
			System.err.println(e1);
		}try{
			con=DriverManager.getConnection(dbname);
		}catch(SQLException e3){
			System.err.print(e3);
		}
	}public ResultSet executeQuery(String sql){
		try{
			stmt=con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
			rs=stmt.executeQuery(sql);
		}catch(SQLException e2){
			System.err.print(e2);
		}
			return rs;
	}public int excuteUpdate(String sql){
		int rt=0;
		try{
			stmt=con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
			rt=stmt.executeUpdate(sql);
		}catch(SQLException ex){
			System.err.print(ex);
		}
		return rt;
	}public void close(){
		try{
			if(con!=null)
				con.close();
		}catch(Exception e){
			System.out.print(e);
		}try{
			if(rs!=null)
				rs.close();
		}catch(Exception e){
			System.out.println(e);
		}
	}
}

⌨️ 快捷键说明

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