- 论坛徽章:
- 0
|
kakasi你好﹐我將你的代碼寫入java文件﹐調試不通過﹐現將我BEAN中所有代碼貼上﹐煩您幫我看一下﹐還有這樣改會不會有其它問題﹗
package com;
import java.io.PrintStream;
import java.sql.*;
import java.text.SimpleDateFormat;
import java.util.*;
class BufferedResultSet implements java.sql.ResultSet
{
public void close() throws SQLException
{
//no need
}
public boolean wasNull() throws SQLException
{
//no need
return false;
}
private int currentIndex;
private List dataList;
private String[] fields;
public BufferedResultSet(ResultSet rs)
{
loadToBuffer(rs);
}
private void loadToBuffer(ResultSet rs)
{
//fill list with all data in rs, and set fields;write yourself
currentIndex = -1;
}
public boolean next() throws SQLException
{
currentIndex++;
return !(currentIndex == dataList.size());
}
public String getString(int columnIndex) throws SQLException
{
Map dataMap = (Map) dataList.get(currentIndex);
return (String)dataMap.get(fields[columnIndex]);
}
public String getString(String columnName) throws SQLException
{
Map dataMap = (Map) dataList.get(currentIndex);
return (String)dataMap.get(columnName);
}
public int getInt(int columnIndex) throws SQLException
{
Map dataMap = (Map) dataList.get(currentIndex);
/////(String) dataMap.get(fields[columnIndex]) decide by loadToBuffer : what did you put
return Integer.parseInt((String) dataMap.get(fields[columnIndex]));
}
}
public class conn1
{
String sDBDriver;
String url;
String user;
String password;
Connection conn;
Statement stmt;
ResultSet rs;
public conn1()
{
sDBDriver = "com.microsoft.jdbc.sqlserver.SQLServerDriver";
url = "jdbc:microsoft:sqlserver://10.99.60.82:1433;DatabaseName=pdm";
user = "sa";
password = "jsdycy163";
conn = null;
stmt = null;
rs = null;
try
{
Class.forName(sDBDriver);
}
catch(ClassNotFoundException classnotfoundexception)
{
System.err.println("connect false(): " + classnotfoundexception.getMessage());
}
}
public Connection conn()
{
try
{
conn = DriverManager.getConnection(url, user, password);
}
catch(Exception exception)
{
System.err.println("connect false(): " + exception.getMessage());
}
return conn;
}
public int executeInsert(String s)
{
int i = -1;
try
{
conn = DriverManager.getConnection(url, user, password);
stmt = conn.createStatement();
stmt.executeUpdate(s);
stmt.close();
conn.close();
i = 1;
}
catch(SQLException sqlexception)
{
System.err.println("executeInsert False():" + sqlexception.getMessage());
i = -1;
}
return i;
}
/* public ResultSet executeQuery1(String s)
{
try
{
conn = DriverManager.getConnection(url, user, password);
stmt = conn.createStatement(1004, 1007);
rs = stmt.executeQuery(s);
}
catch(SQLException sqlexception)
{
System.err.println("executeQuery False():" + sqlexception.getMessage());
}
return rs;
} */
public ResultSet executeQuery(String s) //數據查詢用的代碼
{
BufferedResultSet bRs = null;
Connection conn = null;
Statement stmt = null;
ResultSet rs = null;
try
{
conn = DriverManager.getConnection(url, user, password);
stmt = conn.createStatement(1004, 100 ;
rs = stmt.executeQuery(s);
bRs = new BufferedResultSet(rs);
}
catch(SQLException sqlexception)
{
System.err.println("executeQuery False():" + sqlexception.getMessage());
}
finally
{
if(rs != null)
{
rs.close();
}
if(stmt != null)
{
stmt.close();
}
if(conn != null)
{
conn.close();
}
}
return bRs;
}
public ResultSet executeQuery1(String s) //數據查詢用的代碼
{
BufferedResultSet bRs = null;
Connection conn = null;
Statement stmt = null;
ResultSet rs = null;
try
{
conn = DriverManager.getConnection(url, user, password);
stmt = conn.createStatement(1004, 1007);
rs = stmt.executeQuery(s);
bRs = new BufferedResultSet(rs);
}
catch(SQLException sqlexception)
{
System.err.println("executeQuery False():" + sqlexception.getMessage());
}
finally
{
if(rs != null)
{
rs.close();
}
if(stmt != null)
{
stmt.close();
}
if(conn != null)
{
conn.close();
}
}
return bRs;
}
public int executeUpdate(String s)
{
int i = -1;
try
{
conn = DriverManager.getConnection(url, user, password);
stmt = conn.createStatement();
stmt.executeUpdate(s);
stmt.close();
conn.close();
i = 1;
}
catch(SQLException sqlexception)
{
System.err.println("executeUpdate False():" + sqlexception.getMessage());
i = -1;
}
return i;
}
public int executeDelete(String s)
{
int i = -1;
try
{
conn = DriverManager.getConnection(url, user, password);
stmt = conn.createStatement(1004, 100 ;
stmt.executeUpdate(s);
stmt.close();
conn.close();
i = 1;
}
catch(SQLException sqlexception)
{
System.err.println("executeDelete False():" + sqlexception.getMessage());
i = -1;
}
return i;
}
public void closeStmt()
{
try
{
stmt.close();
}
catch(SQLException sqlexception)
{
sqlexception.printStackTrace();
}
}
public void closeConn()
{
try
{
conn.close();
}
catch(SQLException sqlexception)
{
sqlexception.printStackTrace();
}
}
public String inStr(String s)
{
if(s == null)
s = "";
else
try
{
s = s.trim();
s = s.replace('\'', '\001');
}
catch(Exception exception)
{
exception.printStackTrace(System.err);
}
return s;
}
public String outStr(String s)
{
if(s == null)
s = "";
else
try
{
s = s.replace('\001', '\'');
}
catch(Exception exception)
{
exception.printStackTrace(System.err);
}
return s;
}
public String selectStr(String s)
{
if(s.equals("" )
s = " LIKE '%' ";
else
s = " LIKE '%" + s + "%' ";
return s;
}
public String dataStr(String s)
{
s = s.trim();
Calendar calendar = Calendar.getInstance();
Calendar calendar1 = calendar;
String s1 = calendar.get(1) + "";
Calendar calendar2 = calendar;
Calendar calendar3 = calendar;
String s2 = "00".substring(0, 2 - ((calendar.get(2) + 1) + "" .trim().length()) + ((calendar.get(2) + 1) + "" .trim();
Calendar calendar4 = calendar;
Calendar calendar5 = calendar;
String s3 = "00".substring(0, 2 - (calendar.get(5) + "" .trim().length()) + (calendar.get(5) + "" .trim();
String s4 = s1 + "" + s2 + "" + s3;
int i = -1;
int j = -1;
if(s.equals("" || s == null)
return s4;
i = s.indexOf(47);
if(i != 4)
return s4;
j = s.indexOf(47, 5);
if(j <= 4 || j >= 
{
return s4;
} else
{
String s5 = s.substring(0, i);
String s6 = "00".substring(0, 2 - s.substring(i + 1, j).length()) + s.substring(i + 1, j).trim();
String s7 = "00".substring(0, 2 - s.substring(j + 1).trim().length()) + s.substring(j + 1).trim();
return s5 + s6 + s7 + "";
}
}
public String getDay()
{
SimpleDateFormat simpledateformat = new SimpleDateFormat("yyyy-MM-dd", Locale.getDefault());
java.util.Date date = new java.util.Date();
String s = simpledateformat.format(date);
return s;
}
public String getYear()
{
SimpleDateFormat simpledateformat = new SimpleDateFormat("yyyy/MM/dd HH:mm", Locale.getDefault());
java.util.Date date = new java.util.Date();
String s = simpledateformat.format(date);
return s;
}
public int executeCount(String s)
{
byte byte0 = -1;
if(s.trim() == null || s.trim().equals("" || s.trim().length() != 
byte0 = -1;
else
try
{
String s1 = "update base_fileitem set reader=isnull(reader,0)+1 where loca_bh='" + s.substring(0, 5) + "' and item_bh='" + s.substring(5, + "'";
conn = DriverManager.getConnection(url, user, password);
stmt = conn.createStatement();
stmt.executeUpdate(s1);
stmt.close();
conn.close();
byte0 = 1;
}
catch(SQLException sqlexception)
{
System.err.println("executeCount False():" + sqlexception.getMessage());
byte0 = -1;
}
return byte0;
}
public int executeCount_bbs(String s, String s1, String s2, String s3)
{
byte byte0 = -1;
if(s == null || s.trim().equals("" || s1 == null || s1.trim().equals("" || s2 == null || s2.trim().equals("" )
byte0 = -1;
else
try
{
String s4 = "update mx_bbs set reader1=isnull(reader1,0)+1 where loca_bh='" + s.trim() + "' and item_bh='" + s1.trim() + "' and bh='" + s2.trim() + "' and bh1='001'";
conn = DriverManager.getConnection(url, user, password);
stmt = conn.createStatement();
stmt.executeUpdate(s4);
stmt.close();
conn.close();
byte0 = 1;
}
catch(SQLException sqlexception)
{
System.err.println("executeCount False():" + sqlexception.getMessage());
byte0 = -1;
}
return byte0;
}
public String executeRole(String s, String s1, int i)
{
String s2 = "";
String s3 = "select substring(" + s1.trim() + "," + i + ",1) as role from base_role where gh='" + s.trim() + "'";
try
{
conn = DriverManager.getConnection(url, user, password);
stmt = conn.createStatement();
ResultSet resultset = stmt.executeQuery(s3);
if(resultset.next())
{
s2 = resultset.getString("role");
if(s2 == null)
s2 = "";
else
s2 = s2.trim();
} else
{
s2 = "";
}
stmt.close();
conn.close();
}
catch(SQLException sqlexception)
{
System.err.println("executeCount False():" + sqlexception.getMessage());
s2 = "";
}
return s2;
}
public String executeName(String s)
{
String s1 = "";
String s3 = "select ltrim(rtrim(isnull(xm,''))) as name from base_user where gh='" + s.trim() + "'";
try
{
conn = DriverManager.getConnection(url, user, password);
stmt = conn.createStatement();
ResultSet resultset = stmt.executeQuery(s3);
if(resultset.next())
{
s1 = resultset.getString("name");
if(s1 == null)
s1 = "";
else
s1 = s1.trim();
}
else
{
String s4 = "select ltrim(rtrim(isnull(xm,''))) as name from base_user1 where gh='" + s.trim() + "'";
conn = DriverManager.getConnection(url, user, password);
stmt = conn.createStatement();
ResultSet resultset1 = stmt.executeQuery(s4);
if(resultset1.next())
{
s1 = resultset1.getString("name");
if(s1 == null)
s1 = "";
else
s1 = s1.trim();
}
else
{
s1 = "";
}
}
stmt.close();
conn.close();
return s1;
}
catch(SQLException sqlexception)
{
System.err.println("executeCount False():" + sqlexception.getMessage());
String s2 = "error";
return s2;
}
}
}
備注﹕因我對java剛剛起步﹐望高手們多多指教﹗ |
|