java.sql.SQLSyntaxErrorException: ORA-00942: table or view does not exist error message in netbeans 8.0.1 - sql

when i was trying to delete all records form Oracle database using the following code i got this exception,
QUERYY:: delete from DMUSER.CAMERA_DATA1
java.sql.SQLSyntaxErrorException: ORA-00942: table or view does not exist
Actually here I wanted to create a data mining application using oracle SQL developer and the netbeans IDE. So my workflow is looks like as follow in oracle SQL developer,
The code part that I have used to delete a record from database as follows,
public void deleteData()throws SQLException {
Statement stmt = null;
String query = "delete from DMUSER.CAMERA_DATA1";
System.out.println("QUERYY:: " + query);
try {
stmt = getConnection().createStatement();
int rs = stmt.executeUpdate(query);
if (rs > 0) {
System.out.println("<-------------------Record Deleted--------------->");
}
} catch (SQLException e) {
e.printStackTrace();
} finally {
if (stmt != null) {
stmt.close();
}
}
}
I'm very new to the environment and searched many related questions even in stack but couldn't find exact answer which makes my work successful. Please help me to solve this.

QUERYY:: delete from DMUSER.CAMERA_DATA1
java.sql.SQLSyntaxErrorException: ORA-00942: table or view does not
exist
You need to check, if CAMERA_DATA1 table/view exists in DMUSER schema or not.
Try connecting to same database and schema and check, if table exist or not. If not, then you need to create this table/view in same schema.
Referring to your screenshot provided, I can see CAMERA_DATA table instead of CAMERA_DATA1. So, you can either correct the SQL query to below
String query = "delete from DMUSER.CAMERA_DATA";

Related

SQL syntax error while trying to execute script with multiple CREATE VIEW statements via EntityManager

I would like to create a bunch of SQL views at my Quarkus application startup and I wrote
#Inject
EntityManager em;
public void exec(... sql) {
logger.info("EXECUTING " ...);
sql = "BEGIN\n" + sql + "\nEND";
Query q = em.createNativeQuery(sql);
q.executeUpdate();
}
And my SQL file is following:
CREATE OR REPLACE VIEW My_view_ex AS
SELECT cc.*, If(cc.beautifulName IS NULL, cc.name, cc.beautifulName) canonName FROM My_table cc;
CREATE OR REPLACE VIEW MyView2 AS
...
Unfortunately, it throws exception, saying
java.sql.SQLException: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'CREATE OR REPLACE VIEW My_view_ex AS
SELECT cc.*, If(cc.beautifulName IS NU...' at line 2
If I copy paste the content of sql varible to database client and execute it, then it works, i.e. there is no actually syntax error. Probably it dislikes multiple queries or line ends or something.
What else can be suggested?

.NET Core - ExecuteSqlRaw - IDENTITY_INSERT ON not working

I try to do a raw sql query, becos I need to insert a particular id when injecting data in the SQL db
I set the IDENTITY INSERT flag in C# : SET IDENTITY_INSERT [MyDb-Dev].[dbo].[companies] ON
and when I run the query, it complains the flag is not set properly
Exception thrown: 'Microsoft.Data.SqlClient.SqlException' in Microsoft.EntityFrameworkCore.Relational.dll
Cannot insert explicit value for identity column in table 'companies' when IDENTITY_INSERT is set to OFF.
I tried :
removing [MyDb-Dev]. from the first query but still the same
running setIdentityInsert("companies", "ON"); TWICE and it never triggers any exception
here is my code (it never throws any exception so I guess it works)
private void setIdentityInsert(string table,string value)
{
try
{
var sql = #"SET IDENTITY_INSERT [MyDb-Dev].[dbo].[" + table + "] " + value;
_context.Database.ExecuteSqlRaw(sql);
_logger.LogInformation(sql);
}
catch (Exception e)
{
_logger.LogWarning(e.Message);
}
}
How can I figure if the SET IDENTITY_INSERT query worked correctly ?
Why would that query run without affecting the SQL flag ?
thanks for your precious help
The reason why this fails is because of a different session. Each request is its own session and SET IDENTITY_INSERT = ON is valid only for the current version. You will have to rework using string construction to append your query along side the IDENTITY_INSERT = ON
ok, entity is really not the best partner in this story
one got to do
_context.Database.OpenConnection();
before the first query

Redshift/Java: SQL execute hangs and never returns

The application that im working on runs a sequence of queries on AWS Redshift. Some of the queries take longer to execute due to the data volume.
The queries seem to finish on Redshift when i check the execution details on the server. However, the java application seems to hang indefinitely without throwing any exception or even terminating.
Here's the code that executes the query.
private void execSQLStrings(String[] queries, String dataset, String dbType) throws Exception {
Connection conn = null;
if (dbType.equals("redshift")) {
conn=getRedshiftConnection();
} else if (dbType.equals("rds")){
conn=getMySQLConnection();
}
Statement stmt=conn.createStatement();
String qry=null;
debug("Query Length: " + queries.length);
for (int ii=0;ii<queries.length;++ii) {
qry=queries[ii];
if (dataset != null) {
qry=qry.replaceAll("DATASET",dataset);
}
debug(qry);
stmt.execute(qry);
}
stmt.close();
conn.close();
}
I cant post the query that im running at the moment but it has multiple table joins and group by conditions and its an 800m row table. The query takes about 7~8 mins to complete on the server.
You need to update the DSN Timeout and/ or KeepAlive settings to make sure that your connections stay alive.
Refer: http://docs.aws.amazon.com/redshift/latest/mgmt/connecting-firewall-guidance.html

Yii CDbException.. invalid input syntax for integer: "1,075"

I started receiving this error from a production site since this morning and I'm wondering why I don't get the same in UAT or the developer environment..
Is any one familiar with an error like this ?
CDbException
Description
CDbCommand failed to execute the SQL statement: SQLSTATE[22P02]: Invalid text representation: 7 ERROR: invalid input syntax for integer: "1,076"
Source File
C:\inetpub\wwwroot\framework1.0\db\CDbCommand.php(372)
00360: }
00361:
00362: if($this->_connection->enableProfiling)
00363: Yii::endProfile('system.db.CDbCommand.query('.$this->getText().')','system.db.CDbCommand.query');
00364:
00365: return $result;
00366: }
00367: catch(Exception $e)
00368: {
00369: if($this->_connection->enableProfiling)
00370: Yii::endProfile('system.db.CDbCommand.query('.$this->getText().')','system.db.CDbCommand.query');
00371: Yii::log('Error in querying SQL: '.$this->getText().$par,CLogger::LEVEL_ERROR,'system.db.CDbCommand');
00372: throw new CDbException(Yii::t('yii','CDbCommand failed to execute the SQL statement: {error}',
00373: array('{error}'=>$e->getMessage())));
00374: }
00375: }
00376: }
Attached a screenshot too.. the application is based on yii framework and postgress database.
Quick reply is highly appreciated.
The issue was actually because used number_format() function to a primary key and later in a code section it inputs the formatted number to search query.. i.e select * from user where id = 1,075 (instead of id = 1075)
Changing the number_format() function to apply only on selected areas worked.

java.sql.SQLException: ORA-03115: unsupported network datatype or representation

I'm Using Oracle 11g database. When i try to access data from db it was showing the error java.sql.SQLException: ORA-03115: unsupported network datatype or representation. I'm not understanding what this error means..
my code is :
String uname,pass;
ResultSet rs = null;
response.setContentType("text/html");
PrintWriter out=response.getWriter();
try
{
uname=request.getParameter("uname");
pass=request.getParameter("pass");
Connection con=prepareConnection();
String Query="select uname from passmanager where pass=?";
PreparedStatement ps=con.prepareStatement(Query);
ps.setString(1,pass);
rs=ps.executeQuery(Query);
if (rs.next() && uname.equalsIgnoreCase(rs.getString("uname")) || uname.equalsIgnoreCase(rs.getString("email"))) {
HttpSession session = request.getSession(true);
session.setAttribute("uname", rs.getString(1));
ServletContext context = getServletContext();
RequestDispatcher dispatcher = context
.getRequestDispatcher("/profile");
dispatcher.forward(request, response);
}
Any one help me to solve this problem..
Instead of:
rs = ps.executeQuery(Query);
you should execute:
rs = ps.executeQuery();
Otherwise, you unprepare your statement and lose all parameters because you assign it a new SQL statement (even though it's the same).
This error appears when you try to get a field by name ( rs.getString("uname") in your case) which is not in the resultset.
And like igr said, you are trying to get the email field ( with rs.getString("email") ) and it's not in the query, so this is your error.
I found this conversation because I was getting the same error in an application when I was trying to get a field with an whitespace at the end of the string ( rs.getString("uname ") instead of rs.getString("uname" ).
And I just fix it using the correct name for the field I was getting from the query.
I hope it is useful! ;)
Add email column
select uname, email from passmanager where pass=?