Jump to content
Changes to the Jaspersoft community edition download ×

Use of Parameter for Database name


lconroy

Recommended Posts

Hi,

 

I have been trying to use the following:

 

select * from $P{dbname}.tablename

 

but get an error when running the report.

 

I can use this parameter successfully in other parts of the query and the query works fine when i remove the parameter and replace it with the actual DB name.

 

My question is:

 

Is it OK to use a parameter for the Database name or the table name or is there an error in my approach above.

 

 

ERROR REPORTED in iReports v 1.3.1

ErrorÂfillingÂprint...ÂErrorÂexecutingÂSQLÂstatementÂforÂ:Âfusiontest2

net.sf.jasperreports.engine.JRException:ÂErrorÂexecutingÂSQLÂstatementÂforÂ:Âfusiontest2Â ÂÂÂÂatÂnet.sf.jasperreports.engine.query.JRJdbcQueryExecuter.createDatasource(JRJdbcQueryExecuter.java:121)Â ÂÂÂÂatÂnet.sf.jasperreports.engine.fill.JRFillDataset.createQueryDatasource(JRFillDataset.java:673)Â ÂÂÂÂatÂnet.sf.jasperreports.engine.fill.JRFillDataset.setDatasource(JRFillDataset.java:610)Â ÂÂÂÂatÂnet.sf.jasperreports.engine.fill.JRFillDataset.setParameterValues(JRFillDataset.java:599)Â ÂÂÂÂatÂnet.sf.jasperreports.engine.fill.JRBaseFiller.setParameters(JRBaseFiller.java:864)Â ÂÂÂÂatÂnet.sf.jasperreports.engine.fill.JRBaseFiller.fill(JRBaseFiller.java:702)Â ÂÂÂÂatÂnet.sf.jasperreports.engine.fill.JRBaseFiller.fill(JRBaseFiller.java:660)Â ÂÂÂÂatÂnet.sf.jasperreports.engine.fill.JRFiller.fillReport(JRFiller.java:63)Â ÂÂÂÂatÂnet.sf.jasperreports.engine.JasperFillManager.fillReport(JasperFillManager.java:402)Â ÂÂÂÂatÂnet.sf.jasperreports.engine.JasperFillManager.fillReport(JasperFillManager.java:234)Â ÂÂÂÂatÂit.businesslogic.ireport.IReportCompiler.run(IReportCompiler.java:815)Â ÂÂÂÂatÂjava.lang.Thread.run(UnknownÂSource)Â CausedÂby:Âjava.sql.SQLException:Â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Â''lc'.requests'ÂatÂlineÂ1Â ÂÂÂÂatÂcom.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2926)Â ÂÂÂÂatÂcom.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1571)Â ÂÂÂÂatÂcom.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1666)Â ÂÂÂÂatÂcom.mysql.jdbc.Connection.execSQL(Connection.java:2978)Â ÂÂÂÂatÂcom.mysql.jdbc.Connection.execSQL(Connection.java:2902)Â ÂÂÂÂatÂcom.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:933)Â ÂÂÂÂatÂcom.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:1027)Â ÂÂÂÂatÂnet.sf.jasperreports.engine.query.JRJdbcQueryExecuter.createDatasource(JRJdbcQueryExecuter.java:115)Â ÂÂÂÂ...Â11ÂmoreÂ

Print was not filled. Try using an EmptyDataSource...

Link to comment
Share on other sites

  • Replies 2
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Take a close look at the error messages, particularly this bit:

 

 

Caused by: java.sql.SQLException: 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 ''lc'.requests' at line 1

 

 

Notice how the dB specifier is quoted? This is because you specified $P{dbname}, which puts quotes around its contents. If you want to insert the contents without the quotes you need to specify $P!{dbname}

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...