Description:
public void UpdateSql(String xmlfile,String xpathstr)
{
Document dataDoc = null; //?????????Document
Document newDoc = null; //?????????????xml
String sql="";
Connection conn1=null;
Statement statement=null;
try
{
DocumentBuilderFactory dbfactory = DocumentBuilderFactory.newInstance();
DocumentBuilder docbuilder = dbfactory.newDocumentBuilder();
dataDoc = docbuilder.newDocument();
newDoc = docbuilder.newDocument();
Document sqldoc=getDoc(xmlfile);
ConnectionPool cf = null;
cf=this.dbcf;
conn1=cf.getConnection();
statement = conn1.createStatement(); //ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_UPDATABLE
String sqlstr[]=getNodeValues(sqldoc,xpathstr);
for(int i=0;i<sqlstr.length;i++)
{
sql=sqlstr[i].toString();
statement.execute(sql);
}
String insertsql="insert into userdlxx(userdm,userdlm,userpwd) values('wwwadmin','wwwadmin','"+strDegist("123456")+"')";
int sqln=statement.executeUpdate(insertsql);
}
catch(Exception e)
{
System.out.println("create document error......");
e.printStackTrace();
}
finally
{
if(conn1 != null)
{
try
{
statement.close();
conn1.close();
} catch (SQLException e)
{
// TODO Auto-generated catch block
System.out.println("can't close connection..........");
e.printStackTrace();
}
}
}
}
How to repeat:
//******initsql**********/
use wwwdatatmp;
delimiter //
create trigger uppzxh before insert on jzkxjpz for each row begin set @tmpn1=(select max(pzxh) from jzkxjpz where date(sqrq)=date(now())); if @tmpn1 is null then set new.pzxh=concat(replace(date(now()),'-',''),'0001'); else set new.pzxh=@tmpn1+1; end if; end; //
delimiter ;
//***error**///
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'source initdb.sql' at line 1
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:406)
at com.mysql.jdbc.Util.getInstance(Util.java:381)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1030)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:956)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3515)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3447)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1951)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2101)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2548)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2477)
at com.mysql.jdbc.StatementImpl.execute(StatementImpl.java:741)
at com.mysql.jdbc.StatementImpl.execute(StatementImpl.java:587)
at wwwinitdb.UpdateSql(wwwinitdb.java:131)