I am getting
com.microsoft.sqlserver.jdbc.SQLServerException: Could not allocate space for object
as filegroup is full.
I want a way to identify this SQL exception from other SQL Exceptions.
If I check java.sql.SQLException.venderCode == 1105 will that be enough?And is there any place I can get the description of the 1105 code?
If I check java.sql.SQLException.venderCode == 1105 will that be enough?
Yes, that vendor code (available by calling getErrorCode()) will always map to that error. Just bear in mind it's specific to SQL Server rather than consistent across all SQL implementations.
Various sites like this one detail all the error codes available for SQL server (including 1105.)
Checking the error code alone is sufficient for your need. The returned vendorCode is the SQL Server error number. SQL Server errors and the tokenized message text can be retrieved by the sys.messages DMV. Example for the US English language:
SELECT *
FROM sys.messages
WHERE
message_id = 1105
AND language_id = 1033;
Related
I want to check if an insert fails (due to unique=True index in the collection). If there is an error do something. Bellow is an example of my code.
DBCollection user...;
BasicDBObject Doc = new BasicDBObject(... );
String user_exists = user.insert(Doc).getError(); //insert the doc get error if any
if(user_exists!=null){ //any errors?
user.update(new BasicDBObject(...)); // error exists so do smthng
}
The above as it is does not work. I believe that the String user_exists is always null. How can I make the above work?
I have seen similar SO questions and mention the WriteConcern which can be passed in the insert(). E.g.
coll.insert(dbObj, WriteConcern.SAFE);
sources: SO question
or
Mongo docs
However I do not know which one field should I pass (SAFE, ACKNOWLEDGED, UNACKNOWLEDGED etc..) in order to get the error. Maybe I'm pointed in the wrong direction.
I do not wish to raise an exception just to check if there is an error returned by the insert operation.
If you are using WriteConcern.ACKNOWLEDGED (which I think is also SAFE) you don't need to pollute your code with error checking.
For ACKNOWLEDGED, the driver will automatically issue a getLastError command automatically and raise an exception if anything got wrong, for example duplicate index violation.
Starting from v2.10 of the Java Driver, the default Write Concern is ACKNOWLEDGED
EDIT
I do not wish to raise an exception just to check if there is an error returned by the insert operation.
You shouldn't do this, but in any case:
The insert method indeed returns WriteResult. If it's getError() is null, everything is OK, otherwise it returns something such as E11000 duplicate key error index:.... For this to work, you will have to use WriteConcern.UNACKNOWLEDGED
i try to read data from a MongoDB. and i have a problem:
Exception in thread "main" com.mongodb.MongoException: db already exists with different case other
the exeption throws from here:
DBCursor cur[] = new DBCursor[cursorSize];
...
cur[i].hasNext() // Exeption
what is the problem?
the version of Mongo is 2.10.1
This error indicates that you are trying to create a database that differs by case only from a database name that already exists. For example, if you already have a database called "test", you will get this error trying to create "Test", "TEST", or other variations of upper or lower case for the existing name.
The database name is used in naming the data extent files, so clashes in name could cause Bad Things to happen on case-insensitive file systems.
The MongoDB manual has further details on Naming Restrictions, including case sensitivity and restrictions specific to different operating systems.
The useful part of the error message appears to have been omitted in the question description, but what you should see as part of this message is the name of the existing database as well as the new name that is being rejected.
The corresponding MongoDB 2.4 server code snippet is:
ss << "db already exists with different case other: [" << duplicate << "] me [" << _name << "]";
I think Stennie has very well defined and explained why you might be getting this error. However, in my case, I encountered an interesting case which you or others may also encounter. I had the the database called "HDB" but when I added my user to system.users collection with "db":"hdb" (lower case). So, I spent an hour or so trying to see what could have gone wrong while I was able to login. So, if you get this error make sure you did not accidentally add your user with lower/different case for db name. To confirm this.
1.Log in as the admin/default account run
db.system.users.find().pretty();
and then look for the user name that is getting this error along with the "db" in that json object and compare it against actual database you have.
Run
show dbs;
compare the db you see in step one against the name of db that you see in this step. (the command will show you all the databses you have but clearly you should only be concerned with the ones that you use/see in step one).
I am trying to develop a inventory management system as part of my mini project.
While I try to Insert a data to my Bill_Master Database it returning an error
java.sql.SQLException: [Microsoft][ODBC driver for Oracle][Oracle]ORA-01858: a non-numeric character was found where a numeric was expected
bqty=Integer.parseInt(iqty.getText());
bamount=Float.parseFloat(famnt.getText());
bdsc=Integer.parseInt(dsc.getText());
bnet=Float.parseFloat(netamnt.getText());
billid=Integer.parseInt(billn.getText());
code=Integer.parseInt(icode.getText());
bqty=Integer.parseInt(iqty.getText());
rate=getRate(code);
iamount=rate*bqty;
amt.setText(Float.toString(iamount));
total=total+iamount;
try
{
billdetailid++;
stmt.executeUpdate("insert into Bill_Master values('"+billid+"','"+date+"','"+cname+"','"+total+"','"+bdsc+"','"+total+"','"+uid+"')");//Error Causing Line.
Values are
(1,'27-oct-2013','n/a',900.00,0.0,900.00,'Desk')
Table Structure
Bill_Id (Primary Key INT ):-Stores Bill Number
Bill_Date (Date): Stores Date Of Bill
Customer_Name ( VARCHAR(50)): Customer Name
Total_amt (NUMBER(6)) :Total Bill Amount
Cash_Disc (Number(2)):Discount
Grand_Total(Number(6)):Grand Total
UID(VARCHAR(10)) Stores Who Generated the bill.(EMPLOYEE ID)
Connection Type :ODBC
Please help to solve this issue.
You are putting single quotes around each of your values including bill_Id which is defined as an int. the SQL database is reading this as a string and complaining. Also (as was already pointed out) PreparedStatements make this a lot easier and more secure.
Try this:
stmt.executeUpdate("insert into Bill_Master values('"+billid+"',to_date('"+date+"', 'dd-MON-yyyy'),'"+cname+"','"+total+"','"+bdsc+"','"+total+"','"+uid+"')");
Firstly that is one horrible way of writing SQL queries in java !!!
I am guessing you have just started learning. Please check out PreparedStatements
Data Type related bugs will become easier to debug.
Also that is not the way you write continuous string appends. Check out StringBuilder and String Buffer
I found the exact problem. The reason was I am trying to insert the Label instead of the text in the label.
correct statement is
stmt.executeUpdate("insert into Bill_Master values('"+billid+"','"+date.getText()+"','"+cname.getText()+"','"+total+"','"+bdsc+"','"+total+"','"+uid+"')");
We're running a Java application that saves data to the Oracle RDF triplestore using the Jena adapter. Our version of Oracle is 11gR2.
Recently, we've been getting this error popping up during the save of a large triple.
ERROR http-bio-8080-exec-4 oracle.spatial.rdf.client.jena.GraphOracleSem:
Could not add triple java.sql.SQLException:
ORA-22835: Buffer too small for CLOB to CHAR or BLOB to RAW conversion (actual: 5223, maximum: 4000)
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:439)
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:395)
at oracle.jdbc.driver.T4C8Oall.processError(T4C8Oall.java:802)
at oracle.jdbc.driver.T4CTTIfun.receive(T4CTTIfun.java:436)
at oracle.jdbc.driver.T4CTTIfun.doRPC(T4CTTIfun.java:186)
at oracle.jdbc.driver.T4C8Oall.doOALL(T4C8Oall.java:521)
at oracle.jdbc.driver.T4CPreparedStatement.doOall8(T4CPreparedStatement.java:205)
at oracle.jdbc.driver.T4CPreparedStatement.executeForRows(T4CPreparedStatement.java:1008)
at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1307)
at oracle.jdbc.driver.OraclePreparedStatement.sendBatch(OraclePreparedStatement.java:3753)
at oracle.jdbc.driver.OraclePreparedStatement.processCompletedBindRow(OraclePreparedStatement.java:2112)
at oracle.jdbc.driver.OraclePreparedStatement.executeInternal(OraclePreparedStatement.java:3444)
at oracle.jdbc.driver.OraclePreparedStatement.executeUpdate(OraclePreparedStatement.java:3530)
at oracle.jdbc.driver.OraclePreparedStatementWrapper.executeUpdate(OraclePreparedStatementWrapper.java:1350)
at oracle.spatial.rdf.client.jena.GraphOracleSem.performAdd(GraphOracleSem.java:3509)
at oracle.spatial.rdf.client.jena.OracleBulkUpdateHandler.add(OracleBulkUpdateHandler.java:1226)
at oracle.spatial.rdf.client.jena.OracleBulkUpdateHandler.addIterator(OracleBulkUpdateHandler.java:1257)
at oracle.spatial.rdf.client.jena.OracleBulkUpdateHandler.add(OracleBulkUpdateHandler.java:1278)
at oracle.spatial.rdf.client.jena.OracleBulkUpdateHandler.add(OracleBulkUpdateHandler.java:1268)
at com.hp.hpl.jena.sparql.modify.UpdateProcessorVisitor$1.exec(UpdateProcessorVisitor.java:51)
at com.hp.hpl.jena.sparql.modify.GraphStoreUtils.action(GraphStoreUtils.java:60)
at com.hp.hpl.jena.sparql.modify.UpdateProcessorVisitor.visit(UpdateProcessorVisitor.java:48)
at com.hp.hpl.jena.sparql.modify.op.UpdateInsertData.visit(UpdateInsertData.java:16)
at com.hp.hpl.jena.sparql.modify.UpdateProcessorMain.execute(UpdateProcessorMain.java:34)
at com.hp.hpl.jena.update.UpdateAction.execute(UpdateAction.java:253)
at com.hp.hpl.jena.update.UpdateAction.parseExecute(UpdateAction.java:176)
at com.hp.hpl.jena.update.UpdateAction.parseExecute(UpdateAction.java:143)
at com.hp.hpl.jena.update.UpdateAction.parseExecute(UpdateAction.java:105)
As the error states, it occurs when the data string is greater than 4000 characters. Though it doesn't specify table/column in the error, the Oracle documentation suggests that it's supposed to automatically handle this internally:
RDF_VALUE$ Table:
LONG_VALUE: CLOB - The character string if the length of the lexical value is greater than 4000 bytes. Otherwise, this column has a null value.
VALUE_NAME: VARCHAR2(4000) - This is a computed column. If length of the lexical value is 4000 bytes or less, the value of this column is the concatenation of the values of VNAME_PREFIX column and the VNAME_SUFFIX column.
Some users are not seeing this error, though it may be that they just haven't tried to save something big enough. We've tried clearing out the triplestore model of the user, which seemed to work for a couple days but then came back.
Does anybody have any hints about where to start debugging this? Thank you.
I had the same problem a couple of years ago. Which version of the jena-adapter are you using? I got a patch that solved the problem, maybe you can try and see if it is still availiable on oracle support. This is the instruction I received:
login to support.oracle.com,
then click on Patches & Updates tab
in Patch Search panel, click Search tab, type 10186312 in the text box after Patch Name or Number button.
Click Search button. It should return one match.
Click on the Patch Name 10186312, then Click on Download.
I've a strange situation with a little application in Java using a JDBC-OBDC. I'm inspecting a Database using the DatabaseMetaData Class. When I execute the program, everything works without anyproblem. But when I want to debug to see the values inside the Resulset containing the DatabaseMetaData a java.sql.SQLException is thrown only if I put a breakpoint within the while. Here's my code:
DatabaseMetaData patrol = con.getMetaData();
ResultSet answer = patrol.getTables(null, null, null, null);
while(answer.next()) {
if (answer.wasNull() == false) {
tableNamesAsOne = tableNamesAsOne + answer.getString("TABLE_NAME") + " ";
}
}
answer.close();
Why I cannot put my breakpoint in this section of code??
This is the printStackTrace.
Exception in thread "main" java.sql.SQLException: No data found
at sun.jdbc.odbc.JdbcOdbc.standardError(Unknown Source)
at sun.jdbc.odbc.JdbcOdbc.SQLGetDataString(Unknown Source)
at sun.jdbc.odbc.JdbcOdbcResultSet.getDataString(Unknown Source)
at sun.jdbc.odbc.JdbcOdbcResultSet.getString(Unknown Source)
at sun.jdbc.odbc.JdbcOdbcResultSet.getString(Unknown Source)
at Snooper.inspect(Snooper.java:56)
at Snooper.<init>(Snooper.java:26)
at Snooper.createAndShowGUI(Snooper.java:112)
at Snooper.main(Snooper.java:125)
Line Snooper.java:56 in my code refers to
tableNamesAsOne = tableNamesAsOne + answer.getString("TABLE_NAME") + " ";
Thanks.
I have installed SQL Server to reproduce your problem and verify it.
Short explanation
You must read the values ONLY ONCE and in the ORDER they appear in the SELECT. JdbcOdbc sucks. While debugging, you're reading them multiple times.
Long explanation
What you are doing is inspecting a stateful object in the debugger, which leads to dynamic results.
In this case it's the sun.jdbc.odbc.JdbcOdbcResultSet and executing the expression resultSet.getString(...) multiple times. The first time, it will work (in case your breakpoint suspends the Thread before the resultSet is asked). Then, the second time you (or your debugger) inspects the value of the expression again, the getString() method is called again and this method changes the internal state of the ResultSet object.
Although the method's name suggests it's a simple getter, it's not. It does more than that. It may actually retrieve the data from the database, change its internal position counters etc. You cannot execute the getter methods multiple times.
The ODBC Driver is a very bad thing and of low quality. Expect strange behavior and other dragons. You can get some debug information by enabling JdbcOdbc Tracing. That is done by setting a LogWriter on the DriverManager, before the JdbcOdbc-Bridge is activated:
java.sql.DriverManager.setLogWriter(new PrintWriter(System.out));
Then, you will get verbose debugging output of the JdbcOdbc-Driver like the following. It may help you to debug the problem you have. When debugging, just ensure to store the data retrieved from the ResultSet objects in local objects, so you can inspect them multiple times in the debugger.
DriverManager.getConnection("jdbc:odbc:testdbodbc")
JdbcOdbcDriver class loaded
registerDriver: driver[className=sun.jdbc.odbc.JdbcOdbcDriver,sun.jdbc.odbc.JdbcOdbcDriver#7b479feb]
DriverManager.initialize: jdbc.drivers = null
JDBC DriverManager initialized
trying driver[className=sun.jdbc.odbc.JdbcOdbcDriver,sun.jdbc.odbc.JdbcOdbcDriver#7b479feb]
*Driver.connect (jdbc:odbc:testdbodbc)
JDBC to ODBC Bridge: Checking security
No SecurityManager present, assuming trusted application/applet
JDBC to ODBC Bridge 2.0001
Current Date/Time: Wed Jan 26 00:31:27 CET 2011
Loading JdbcOdbc library
Allocating Environment handle (SQLAllocEnv)
hEnv=115724512
Allocating Connection handle (SQLAllocConnect)
hDbc=116219184
Connecting (SQLDriverConnect), hDbc=116219184, szConnStrIn=DSN=testdbodbc
RETCODE = 1
WARNING - Generating SQLWarning...
SQLWarning: reason([Microsoft][ODBC SQL Server Driver][SQL Server]Changed database context to 'master'.) SQLState(01000) vendor code(5701)
SQLWarning: reason([Microsoft][ODBC SQL Server Driver][SQL Server]Changed language setting to us_english.) SQLState(01000) vendor code(5703)
*Connection.getMetaData
*DatabaseMetaData.getDriverName
Get connection info string (SQLGetInfo), hDbc=116219184, fInfoType=6, len=300
SQLSRV32.DLL
*DatabaseMetaData.getDriverVersion
Get connection info string (SQLGetInfo), hDbc=116219184, fInfoType=7, len=300
06.01.7600
*DatabaseMetaData.getDriverName
Get connection info string (SQLGetInfo), hDbc=116219184, fInfoType=6, len=300
SQLSRV32.DLL
Driver name: JDBC-ODBC Bridge (SQLSRV32.DLL)
*DatabaseMetaData.getDriverVersion
P.S. And this was the reproduced exception, including line numbers of the Sun code for JDK 1.6.0_22. As you can see in the first line, this is what is printed out on the console when I inspected the getString() method.
Get string data (SQLGetData), hStmt=108067024, column=3, maxLen=257
RETCODE = 100
ERROR - No data found
java.sql.SQLException: No data found
at sun.jdbc.odbc.JdbcOdbc.standardError(JdbcOdbc.java:7138)
at sun.jdbc.odbc.JdbcOdbc.SQLGetDataString(JdbcOdbc.java:3907)
at sun.jdbc.odbc.JdbcOdbcResultSet.getDataString(JdbcOdbcResultSet.java:5698)
at sun.jdbc.odbc.JdbcOdbcResultSet.getString(JdbcOdbcResultSet.java:354)
at sun.jdbc.odbc.JdbcOdbcResultSet.getString(JdbcOdbcResultSet.java:411)
at sandbox.DatabaseMetadataTest.testDBMetadata(DatabaseMetadataTest.java:27)
Yeah, the debugger runs in a different thread than the metadata obtained by con.getMetaData();... so, you know, it's a different transaction with a different metadata.
Well, ok, that would be my 1st guess. I have not looked into Obdc driver source code to confirm.
Edit:
thanks for mhaller excellent remark a made a 2nd look/guess: you call wasNull() prematurely, it has meaning after some get operation of the ResultSet. Copy from javadoc
* Note that you must first call one of the getter methods
* on a column to try to read its value and then call
* the method <code>wasNull</code> to see if the value read was
* SQL <code>NULL</code>.
phew, me sucks tonight!