MSsql mssql = new MSsql(SQL_FIND_BY_WORKTIME);
这个是什么?
这个是什么?
解决方案 »
- 这个怎么写?
- hibernate 多对多 用Criteria怎么查询
- hibernate做select操作时有必要commit吗?
- 奇怪,myeclipse blue将文件提交到svn后,本地文件回退到旧的版本?
- 在Jsp中,有EL表达式${10*10 ne 10}结果是什么
- java报表的问题。JFreeChart谁会使用阿?高手指教!!!!!!急急急急急!
- 谁知道怎么在页面里提交进数据库一些东西,如何在一个树中动态的把添加进的东西实时显示出来?
- 为什么在函数中不能调用.class
- Servlet中的getParameter 是不是实现了多语言的转换??
- (SOS 在线等待,马上给分)请看看定制JSP TagLib的问题,为什么说设有setter
- jbuilder中光标指示的位置不正确?
- jsp设置好了错误跳转页面,但无法正确跳转。。
import java.sql.*;
import javax.sql.*;
import java.io.*;
import javax.naming.*;public class MSsql{private Connection conn=null;
private Statement stmt=null;
private PreparedStatement prepstmt=null;
/**
*
*
*
**/
public MSsql(){
try{
getDataSource();
stmt=conn.createStatement();}catch(Exception e){
System.err.println("MSsql init error:"+e);}
}
private void getDataSource() {
try {
Context ctx = new InitialContext();
if (ctx == null)
throw new Exception("Boom - No Context"); DataSource ds =
(DataSource) ctx.lookup("java:comp/env/jdbc/userDB");
if (ds != null)
conn = ds.getConnection(); } catch (Exception e) {
System.err.println("getDataSource() error: " + e);
}
}
/**
*
*
*
**/
public MSsql(String sql){
try{
String url="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=rmyy";
String user="sa";
String password="sa";
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance();
conn=DriverManager.getConnection(url,user,password);
prepareStatement(sql);}catch(Exception e){
System.err.println("MSsql init error:"+e);}}
public Connection getConnection(){
return conn;
}
public void prepareStatement(String sql) throws SQLException{
prepstmt=conn.prepareStatement(sql);
}
public void setString(int index, String value) throws SQLException {
prepstmt.setString(index, value);
}
public void setInt(int index, int value) throws SQLException {
prepstmt.setInt(index, value);
}
public void setBoolean(int index, boolean value) throws SQLException {
prepstmt.setBoolean(index, value);
}
public void setDate(int index, Date value) throws SQLException {
prepstmt.setDate(index, value);
}
public void setLong(int index, long value) throws SQLException {
prepstmt.setLong(index, value);
}
public void setFloat(int index, float value) throws SQLException {
prepstmt.setFloat(index, value);
}
public void setBinaryStream(int index, InputStream in, int length) throws SQLException {
prepstmt.setBinaryStream(index, in, length);
}
public void clearParameters() throws SQLException {
prepstmt.clearParameters();
}
public PreparedStatement getPreparedStatement() {
return prepstmt;
}
public Statement getStatement() {
return stmt;
}
public ResultSet executeQuery(String sql) throws SQLException {
if (stmt != null){
return stmt.executeQuery(sql);
} else
return null;
}/**
*
*
*
**/
public ResultSet executeQuery() throws SQLException {
if (prepstmt != null) {
return prepstmt.executeQuery();
} else
return null;
} /**
*
*
*
**/
public void executeUpdate(String sql) throws SQLException {
if (stmt != null)
stmt.executeUpdate(sql);
}
/**
*
*
*
**/
public void executeUpdate() throws SQLException {
if (prepstmt != null)
prepstmt.executeUpdate();
}/**
*
*
*
**/
public void close() {
try {
if (stmt != null) {
stmt.close();
stmt = null;
}
if (prepstmt != null) {
prepstmt.close();
prepstmt = null;
}
conn.close();
conn = null;
} catch (Exception e) {
System.err.println("MSsql close error: " + e);
}
}