at com.mysql.jdbc.jdbc2.Statement.executeQuery(Unknown Source)
at com.codestudio.sql.PoolManStatement.executeQuery把 mysql何它下面所有的文件拷贝到codestudio文件加所在的com文件加中,
让mysql和codestudio同在一个com文件夹中,并且删除mysql原来所在的com
文件加机器里面的所有的东西good luck !
at com.codestudio.sql.PoolManStatement.executeQuery把 mysql何它下面所有的文件拷贝到codestudio文件加所在的com文件加中,
让mysql和codestudio同在一个com文件夹中,并且删除mysql原来所在的com
文件加机器里面的所有的东西good luck !
如:
java.util.Date
和
java.sql.Date
部分代码:
package com.smartdot.standard;
import com.codestudio.sql.*;
import java.sql.*;
public class DBAction
{
public java.sql.Statement Stmt; //SQL语句对象
public java.sql.PreparedStatement PStmt;
public java.sql.ResultSet Rs; //结果集对象
public java.sql.Connection Con;
public String strCon; //数据库连接字符串
public String strSQL; //SQL语句
public String TableName;//描述表名
.....
......
public void executeQuery(String strSQL) throws
SQLException
{
Rs=Stmt.executeQuery(strSQL);
}}其子类也就是调用的bean 的代码:// Java Document
package com.smartdot.standard;
import com.smartdot.standard.DBAction;public class PublicUser extends DBAction
{ //定义变量(与数据库的字段名字一一对应)
public String TableName="PublicUser";
public String[] aFieldName;
public String[] aFieldValue;
public String UserID;
public String UserPassword;
public String NickName;
public String RealName;
public int Sex;
public String Company;
public String Mobile;
public String Tel;
public String Email;
public String Favor;
public String Re;
public String Profile;
//定义用户登陆成功与否
public boolean blnLogin;
//构造函数
public PublicUser() throws Exception
{
blnLogin=false;
}
//检查登陆用户密码的合法性,如果合法就返回true,不合法返会false
public boolean checkUser(String strUserID,String strPassword) throws Exception
{
executeQuery("select * from "+TableName+" where userid="+getString(strUserID)+" and UserPassword="+getString(strPassword));
if(Rs.next())
{
UserID=Rs.getString(1);
UserPassword=Rs.getString(2);
NickName=Rs.getString(3);
RealName=Rs.getString(4);
Sex=Rs.getInt(5);
Company=Rs.getString(6);
Mobile=Rs.getString(7);
Tel=Rs.getString(8);
Email=Rs.getString(9);
Favor=Rs.getString(10);
Re=Rs.getString(11);
Profile=Rs.getString(12);
blnLogin=true;
return true;
}
else
{
return false;
}
}
//是否存在此用户
public boolean existUser(String strUserID) throws Exception
{
executeQuery("select * from "+TableName+" where userid="+getString(strUserID));
if (getRsCounts()==0)
{
return false;
}
else
{
return true;
}
}
}
package com.smartdot.standard;
import com.codestudio.sql.*;
import java.sql.*;
public class DBAction
{
public java.sql.Statement Stmt; //SQL语句对象
public java.sql.PreparedStatement PStmt;
public java.sql.ResultSet Rs; //结果集对象
public java.sql.Connection Con;
public String strCon; //数据库连接字符串
public String strSQL; //SQL语句
public String TableName;//描述表名
public String Condition;//描述条件语句
public String[] aFieldName;//描述表的字段名
public String[] aFieldValue;//描述表的字段值
public int[] aFieldAttribute;//描述字段是不是字符串,是为1,不是为0
public DBAction() throws Exception
{
openDB();
}
public DBAction(String strTableName) throws Exception
{
TableName=strTableName;
openDB();
}
//打开连接池,建立连接和创建stmt对象。
public void openDB() throws Exception
{
strCon="jdbc:poolman://Testdb";
Class.forName("com.codestudio.sql.PoolMan").newInstance();
Con = DriverManager.getConnection(strCon);
Stmt = Con.createStatement(java.sql.ResultSet.TYPE_SCROLL_SENSITIVE ,java.sql.ResultSet.CONCUR_READ_ONLY); //执行SQL语句
}
//增加数据库一条记录
public void executeAdd(String strTableName,String[] astrFieldName ,String[] astrFieldValue) throws Exception
{
String strSQL;
if (astrFieldName.length==1)
{
strSQL="insert into "+strTableName+"("+astrFieldName[0]+") values("+astrFieldValue[0]+")";
}
else
{
strSQL="insert into "+strTableName+"(";
//加字段
for (int i=0;i<astrFieldName.length ;i++ )
{
if (i==astrFieldName.length-1)
{
strSQL=strSQL+astrFieldName[i];
}
else
{
strSQL=strSQL+astrFieldName[i]+",";
}
}
strSQL=strSQL+") values(";
//加字段值
for (int i=0;i<astrFieldValue.length ;i++ )
{
if (i==astrFieldValue.length-1)
{
strSQL=strSQL+astrFieldValue[i];
}
else
{
strSQL=strSQL+astrFieldValue[i]+",";
}
}
strSQL=strSQL+")";
}
strSQL=strSQL;
executeUpdate(strSQL); }
//修改数据库
public void executeEdit(String strTableName,String strCondition,String[] astrFieldName ,String[] astrFieldValue) throws Exception
{
String strSQL;
if (astrFieldName.length==1)
{
strSQL="update "+strTableName+" set "+astrFieldName[0]+"="+astrFieldValue[0]+" "+strCondition;
}
else
{
strSQL="update "+strTableName+" set ";
//加字段
for (int i=0;i<astrFieldName.length ;i++ )
{
if (i==astrFieldName.length-1)
{
strSQL=strSQL+astrFieldName[i]+"="+astrFieldValue[i];
}
else
{
strSQL=strSQL+astrFieldName[i]+"="+astrFieldValue[i]+",";
}
} strSQL=strSQL+strCondition;
}
strSQL=strSQL;
executeUpdate(strSQL);
}
//执行sql语句
public void executeUpdate(String strSQL) throws Exception
{ Stmt.executeUpdate(strSQL); }
//关闭数据库连接
public void closeDB() throws SQLException
{
if (Rs!=null)
{
Rs.close();
}
if (PStmt!=null)
{
PStmt.close();
}
if (Stmt!=null)
{
Stmt.close();
}
if (Con!=null)
{
Con.close();
}
}
//用preparestament操作数据库
public void setPStmt(String strSQL) throws SQLException
{
PStmt=Con.prepareStatement(strSQL);
}
//数据库查询,并判断返回结果集合的记录数
//
public void executeQuery(String strSQL) throws SQLException
{ Rs=Stmt.executeQuery(strSQL);
}
//返回记录集合的数
public int getRsCounts(ResultSet Rs) throws Exception
{
int intCounts=1;
if (Rs.next())
{
while (Rs.next())
{
intCounts++;
}
return intCounts; }
else
return 0; }
//返回类属性Rs记录集合的记录数
public int getRsCounts() throws Exception
{
int intCounts=1;
if (Rs.next())
{
while (Rs.next())
{
intCounts++;
}
return intCounts; }
else
return 0; }
//记录集指针的移动
public boolean Move(ResultSet Rs,int intPosition) throws Exception
{
Rs.first();
if (intPosition<=getRsCounts(Rs))
{ for (int i=1;i< intPosition-1; )
{
Rs.next();
}
return true;
}
else
return false;
}
//对类属性Rs记录集指针的移动
public boolean Move(int intPosition) throws Exception
{
Rs.first();
if (intPosition<=getRsCounts(Rs))
{ for (int i=1;i< intPosition-1; )
{
Rs.next();
}
return true;
}
else
return false;
}
//获得字符串
public String getString(String strValue)
{
if (strValue!=null)
{
int i=-2;
while((i=strValue.indexOf("'",i+2))!=-1)
{
strValue=strValue.substring(0,i)+"'"+strValue.substring(i);
}
return "'"+strValue+"'";
}
else
{
return "null";
} }
//格式话字段值数组aField,然后把此写成sql语句插入到数据库
public String[] formatField(String[] astrFieldValue,int[] aFieldAttribute)
{
String[] astrTemp=new String[astrFieldValue.length];
for (int i=0;i<astrFieldValue.length ;i++ )
{
if (aFieldAttribute[i]==1)
{
astrTemp[i]=getString(astrFieldValue[i]);
}
else
{
astrTemp[i]=astrFieldValue[i];
} }
return astrTemp; }
//得到表的每个字段的名字
public boolean getFieldName(String strTableName) throws Exception
{
int intCounts=0;
int i=0;
String strTemp;
if (strTableName!=null || strTableName.equals(""))
{ executeQuery("desc "+strTableName);
while (Rs.next())
{
intCounts++; }
aFieldName=new String[intCounts];
aFieldValue=new String[intCounts];
Rs.first();
do
{
aFieldName[i]=Rs.getString(1);
strTemp=Rs.getString(2);
if (strTemp.indexOf("text")>=0 || strTemp.indexOf("char")>=0 || strTemp.indexOf("blob")>=0)
{
aFieldAttribute[i]=1; }
else
{
aFieldAttribute[i]=0;
} i++; }
while (Rs.next()); }
closeDB();
return true; }
//得到表的每个字段的名字参数取类的属性TableName
public boolean getFieldName() throws Exception
{
int intCounts=0;
int i=0;
String strTemp;
if (TableName!=null || TableName.equals(""))
{ executeQuery("desc "+TableName);
while (Rs.next())
{
intCounts++; }
aFieldName=new String[intCounts];
aFieldValue=new String[intCounts];
Rs.first();
do
{
aFieldName[i]=Rs.getString(1);
strTemp=Rs.getString(2);
if (strTemp.indexOf("text")>=0 || strTemp.indexOf("char")>=0 || strTemp.indexOf("blob")>=0)
{
aFieldAttribute[i]=1; }
else
{
aFieldAttribute[i]=0;
} i++; }
while (Rs.next());
closeDB();
return true; }
else
return false; }
}
你可以把这句
Stmt = Con.createStatement(java.sql.ResultSet.TYPE_SCROLL_SENSITIVE ,java.sql.ResultSet.CONCUR_READ_ONLY);
换成:
Stmt=Con.createStatement();试一下看看.
throws Exception
很难调试。看似简单,实际要多做许多事情。
java.lang.NullPointerException
at _0002fRegisterme_0002ejspRegisterme_jsp_1._jspService(_0002fRegisterme_0002ejspRegisterme_jsp_1.java:100)你打开_0002fRegisterme_0002ejspRegisterme_jsp_1.java这个文件,
这个文件是tomcat将.jsp文件转换成servlet文件后产生的,
在c:\tomcat\work目录下,然后根据出错的行数(100)看错误出在哪行了。
我依照你的方法打开了该文件,可是所告诉我 的出错行只有一个大括号,且并没有大括号不匹配的情形发生。我现在怀疑问题的关键是这一句:
java.lang.NullPointerException
可是哪个指针是空的呢?再者,为什么错误有时有,有时没有呢?又为什么重启tomcat,之后又肯定就没问题了呢?
非常奇怪,非常郁闷。
我也用一个类封装了对数据库的操作,
可是在servlet中提交对数据库的操作,
第一次java.lang.NullPointerException,
刷新一次就可以正确提交。我也百思不得其解,
后来一个四星高手告诉我,
在连接字符串(我用SQL Server2000)中加一个参数:
SelectMethod=cursor;
就搞定了。你应该往这方面想想。
不一定是你代码出错了。
这样问题是解决了但我觉得还是没有摸清问题的根本。
不管怎样非常谢谢大家,毕竟在网上看一个问题有些不便,并且我的代码实在有些过长了。呵呵。结贴送分。