jsp页面:
sqlstr= "where a.status=1 ";
String[][] jbcj= ld.getValues("Pt_activities a","a.Act_id","sqlstr");
javabean:private String[][] getValues() throws JavaBeanException
{
Connection conn = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
int rowCount = 0;
try
{
conDataBase connData=new conDataBase();
conn = connData.getPool().getConnection();//dataSource.getConnection(); if (whereClause == null)
pstmt = conn.prepareStatement("SELECT COUNT(*) FROM " + tableName);
else
pstmt = conn.prepareStatement("SELECT COUNT(*) FROM " + tableName + " " + whereClause); rs = pstmt.executeQuery();
if(rs.next())
rowCount = rs.getInt(1);
rs.close();
pstmt.close();
if (whereClause == null)
pstmt = conn.prepareStatement("SELECT " + firstFieldName + " FROM " + tableName);
else
pstmt = conn.prepareStatement("SELECT " + firstFieldName + " FROM " + tableName + " " + whereClause); rs = pstmt.executeQuery();
int cnt;
int field = 1;
for (int k =0;k<firstFieldName.length();k++)
{
cnt = firstFieldName.indexOf(",",k);
if (cnt != -1)
{
field = field + 1;
k = cnt;
}
}
String[][] values = new String[rowCount][field]; for (int i = 0; i < rowCount; i++)
{
try{
if (rs.next()) {
for (int m =0;m<field;m++)
{
String a = rs.getString(m+1);
if (a!=null)
values[i][m] = a;
else
values[i][m]="";
}
}
}
catch(Exception e)
{
break;
}
} return values;
}
catch(SQLException e)
{
throw new JavaBeanException(e.getMessage());
}
finally
{
if (rs != null)
try { rs.close(); rs= null;} catch(SQLException ignore) {}
if (pstmt != null)
try { pstmt.close(); pstmt= null;} catch(SQLException ignore) {}
if (conn != null)
try { conn.close(); conn= null;} catch(SQLException ignore) {}
}
}
不知道为什么如果再查询语句中将表名from Pt_activities a这么写就会报ORA-00933: SQL command not properly ended 错误,如果直接from Pt_activities 就没问题
sqlstr= "where a.status=1 ";
String[][] jbcj= ld.getValues("Pt_activities a","a.Act_id","sqlstr");
javabean:private String[][] getValues() throws JavaBeanException
{
Connection conn = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
int rowCount = 0;
try
{
conDataBase connData=new conDataBase();
conn = connData.getPool().getConnection();//dataSource.getConnection(); if (whereClause == null)
pstmt = conn.prepareStatement("SELECT COUNT(*) FROM " + tableName);
else
pstmt = conn.prepareStatement("SELECT COUNT(*) FROM " + tableName + " " + whereClause); rs = pstmt.executeQuery();
if(rs.next())
rowCount = rs.getInt(1);
rs.close();
pstmt.close();
if (whereClause == null)
pstmt = conn.prepareStatement("SELECT " + firstFieldName + " FROM " + tableName);
else
pstmt = conn.prepareStatement("SELECT " + firstFieldName + " FROM " + tableName + " " + whereClause); rs = pstmt.executeQuery();
int cnt;
int field = 1;
for (int k =0;k<firstFieldName.length();k++)
{
cnt = firstFieldName.indexOf(",",k);
if (cnt != -1)
{
field = field + 1;
k = cnt;
}
}
String[][] values = new String[rowCount][field]; for (int i = 0; i < rowCount; i++)
{
try{
if (rs.next()) {
for (int m =0;m<field;m++)
{
String a = rs.getString(m+1);
if (a!=null)
values[i][m] = a;
else
values[i][m]="";
}
}
}
catch(Exception e)
{
break;
}
} return values;
}
catch(SQLException e)
{
throw new JavaBeanException(e.getMessage());
}
finally
{
if (rs != null)
try { rs.close(); rs= null;} catch(SQLException ignore) {}
if (pstmt != null)
try { pstmt.close(); pstmt= null;} catch(SQLException ignore) {}
if (conn != null)
try { conn.close(); conn= null;} catch(SQLException ignore) {}
}
}
不知道为什么如果再查询语句中将表名from Pt_activities a这么写就会报ORA-00933: SQL command not properly ended 错误,如果直接from Pt_activities 就没问题
解决方案 »
- oracle导出和导入数据
- 同时对一个表并发多个INSERT,存储过程能否实现?
- 如何在oracle 客户端的command窗口运行SQL语句
- 编辑CLOB字段的问题?
- 在oracle中怎么区分和上次查询不一样的内人
- 用户要有什么权限才可以登陆到sqlplus和oem?
- 如何将两个字段分别赋给两个变量!
- Oracle备份时可以正常使用吗?急死了,经理等着我解决,大家帮个忙啊(全身家当)----备份与正常使用
- 关于oracle登陆配置和java连接数据库问题
- 数据泵导入问题求解,据说是Oracle11gR2的Bug?
- ***多线程连接数据库报错!
- 使当前连接的操作不产生归档日志的sql语句如何写?
用System.out.println把结果直接打印出来看看SQL有没有问题?
then { .....}
else { .... }