Error : In fetching data from DatabaseClosed Connection - selenium-webdriver

I am facing a strange problem while running two test-cases that is present in a TestSuite. The Test suite comprises of 15 Test cases, and these two are 9th and 10 th Tc's respectively.
When i am running only these two test cases both are running fine, but with the whole test suite running these two are not present in the report.(Totally getting skipped)
Both the test cases having a function that executes a databases query and fetches a patient name from database and in console we have seen this is the root cause behind the error.
We are facing "Error :In fetching data from Database Io exception: Connection reset"--9th Tc
In fetching data from DatabaseClosed Connection"--10th Tc
The code we have written is below to fetch the patient name:
try
{
stmt =con.createStatement(); //public static java.sql.Statement stmt;public static ResultSet rs;public static Connection con; these 3 we declared in driver script
rs=stmt.executeQuery("select d.id, c.first_name, c.last_name, d.ssn from Table1 d, Table2 c where c.id=d.contact_id and d.facility_id='"+facilityID+"' and d.security_id='"+securityID+"' and <Some condition> and d.id not in (<Some data>);
if (rs.next() == true){
DBFirstName=rs.getString(2);
DBLastName=rs.getString(3);
DBFullName = DBLastName +", " +DBFirstName;
System.out.println("DB Full Name ="+DBFullName);
}else{
System.out.println("Inside else");
return "Fail :Unable to fetch Patient data(lastname) from database";
}
}
catch(Throwable t)
{
APPLICATION_LOGS.debug("Error : In fetching data from Database" +t.getMessage());
System.out.println("Error : In fetching data from Database" +t.getMessage());
}
rs.close();
stmt.close();
Please let me know if anyone having any idea.
Thanks in advance.
Nilanjan.

Please check if database connection has been open . Con.open() might do the work. And also try checking the stack trace i guess it is coming as soon as you start using the connection as it is not open. Please check and tell

Related

Postgresql with golang, questions

I have created an Api with golang and postgresql as database.
after several requests, the API crashes with an error 500 and a log that displays
pq : sorry , too many customers already
At first it was because I did not close rows when i select, so i have rows.close() all.
But it's not that because i have already this error.
Then saw the launch of the database takes only 3ms, I thought I should start and close the database on every request to reset all connections,
but thinking about it a little more, this is nonsense.
So I ask you, how this error works , is that the client connections are reset after a certain time or connection is cut off until a server reboot for client?
If it resets after a certain time , what are the disadvantages of increasing the maximum number of client connection?
My code:
I open my db like this at start of program :
var gest Gestion
type Gestion struct {
Db *sql.DB
DbLog *sql.DB
}
func InitDbUser() *sql.DB {
dbinfo := fmt.Sprintf("user=%s password=%s dbname=%s sslmode=disable", DB_USER, DB_PASSWORD, DB_NAME)
db, err := sql.Open("postgres", dbinfo)
LogFatalError(err)
err2 := db.Ping()
LogFatalError(err2)
return db
}
func main() {
gest.Db = InitDbUser()
defer gest.Db.Close()
//routing is here
}
And when i use this request in my psql :
select min_val,max_val from pg_settings where name='max_connections';
I get hat :
min_val | max_val
---------+---------
1 | 8388607
Sorry for my english, i hope you understand what I ask :)
You can check the max_connection setting of PG, that might be the problem here:
select min_val,max_val from pg_settings where name='max_connections'

save huge xml from sql to web

In sqlserver I have a function which generates a complex xml of all products with several tables joined: location, suppliers, orders etc.
No problem in that, it runs in 68 sec and produces around 450MB.
It should only be called occationally during migration to another server, so it doesn't matter it takes some time.
I want to make this available for download over webserver.
I've tried some variations of this in classic asp:
Response.Buffer = false
set rs=conn.execute("select cast(dbo.exportXML() as varchar(max)) as res")
response.write rs("res")
But I just get a standard
An error occurred on the server when processing the URL. Please contact the system administrator.
If you are the system administrator please click here to find out more about this error.
Not my usual custom 500-errorhandler, so I'm not sure how to find the error.
The problem is in response.write rs("res"), if i just do
temp = rs("res")
the script runs, but displays nothing of cause; if I then
response.write temp
I get the same failure.
So the problem is writing such a ling string.
Can I save the file from tsql directly; and run the job periodically from sql agent?
I found that there seems to be a limit on how much data can be written at once using Response.Write. The workaround I used was to break the data into chunks like this:
Dim Data, Done
Done = False
Do While Not Done
Data = RecordSet(0).GetChunk(8192)
If Not Len(Data) = 0 Then
Response.Write Data
Else
Done = True
End If
Loop
Try this:
Response.ContentType = "text/xml"
rs.CursorLocation = 3
rs.Open "select cast(dbo.exportXML() as varchar(max)) as res",conn
'Persist the Recordset in XML format to the ASP Response object.
'The constant value for adPersistXML is 1.
rs.Save Response, 1

Apache camel getting Oracle database generated ID

I am using a camel jdbc component to insert a record into an Oracle table. the insert uses a sequence to populate a primary key ID column.
INSERT INTO my_table (id, data) VALUES (my_seq.nextval, 'some data')
The relevant part of the route looks like below:
from("some end point here")
.process(preInsertProcessor)
.to("jdbc:myDataSource")
.process(new Processor() {
public void process(Exchange exchange) throws Exception {
LOGGER.info("Extracting database generated id");
// This list is null
List<Integer> ids = exchange.getIn().getHeader(
JdbcConstants.JDBC_GENERATED_KEYS_DATA, List.class);
});
Inside the preInsertProcessir I set the message body to be my insert statement and also set some two header values to instruct camel I want the generated ID back:
message.setBody("INSERT INTO my_table (id, data) VALUES (my_seq.nextval, ?:data)");
message.setHeader("data", "some data");
message.setHeader(JDBC_RETRIEVE_GENERATED_KEYS, true);
message.setHeader(JDBC_GENERATED_COLUMNS, new String[]{"ID"});
End if I look at the logs I can see:
[DEBUG] org.apache.camel.component.bean.MethodInfo - Setting bean invocation result on the OUT message: [Message: INSERT INTO my_table(id, data)VALUES (my_seq.nextval, :?data]
[DEBUG] org.apache.camel.spring.spi.TransactionErrorHandler - Transaction begin (0x1de4bee0) redelivered(false) for (MessageId: ID-MELW1TYGC2S-62650-1438583607644-0-8 on ExchangeId: ID-MELW1TYGC2S-62650-1438583607644-0-9))
[INFO ] au.com.nab.cls.router.non.repudiation.GeneratedIdExtractor - Extracting database generated id
[DEBUG] org.apache.camel.processor.MulticastProcessor - Done sequential processing 1 exchanges
[DEBUG] org.apache.camel.spring.spi.TransactionErrorHandler - Transaction commit (0x1de4bee0) redelivered(false) for (MessageId: ID:414d5120445041594855423120202020027844552045b302 on ExchangeId: ID-MELW1TYGC2S-62650-1438583607644-0-7))
If I get it well from the look of the logs the insert would be executed and my final processor should be able to get the generated ID. In reality what happens is that no record gets inserted and no ID is present in the header of the message. Without the final processor everything works fine.
Obviously I am doing something wrong here but I cannot figure out what. I am aware I could use a message en-richer to get the ID before the insert but I would prefer to avoid an extra database trip.
Thank you in advance for your inputs.
UPDATE
I put a break point in org.apache.camel.component.jdbc.JdbcProducer and found out the reason for not having the INSERT executed and consequently not getting the ID back.
// JdbcProducer code; creating a prepared statement part
if (shouldRetrieveGeneratedKeys) {
...
} else if (expectedGeneratedColumns instanceof String[]) {
// Execution gets herestatement
ps = conn.prepareStatement(preparedQuery, (String[]) expectedGeneratedColumns);
...
}
// Expected count returned here is 2
int expectedCount = ps.getParameterMetaData().getParameterCount();
if (expectedCount > 0) {
...
// And here I get the crash:
// java.sql.SQLException: Number of parameters mismatch. Expected: 2, was:1
getEndpoint().getPrepareStatementStrategy().populateStatement(ps, it, expectedCount);
}
This is where my research stopped as digging too much in the various three parties code is not really easy. I suspect one of the following two options are the cause:
I am still not doing it the right way
A camel bug which does not work as expected when header contains both named parameters and retrieve generated keys settings
Please advise about any fix or work around.
Thanks again
I also ran into this. My workaround:
Use camel-sql instead of camel-jdbc. Add parametersCount option to the endpoint URL (in adddition to setHeader(SqlConstants.SQL_RETRIEVE_GENERATED_KEYS, constant(true)) and setHeader(SqlConstants.SQL_GENERATED_COLUMNS, constant(new String[] {"ID_COLUMN_NAME"})).
Update: Works with 11.2.0.4 jdbc driver (does not work with 12.2.0.1 jdbc driver).

file is encrypted or is not a database , QT

Sorry for posting this even though there're a few posts about this , but they're not helping.
I'm using sqlite with QT , I wanted to do a simple query but it gives me this error:
file is encrypted or is not a database Unable to execute statement
Some posts' comments say that the DB may be corrupt, I used another program and created a test table from scratch and still has the same problem, this is the code:
QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
db.setDatabaseName("AdmissionTestDB.sql");
db.open();
if(db.isOpen())
{
QSqlQuery q = db.exec("SELECT * FROM USERS");
if(!q.lastError().isValid())
{
qDebug()<<"works!";
while(q.next())
{
qDebug()<<q.value(8).toString();
}
}
else
qDebug()<<"---db failed to open! , error: "<<q.lastError().text();
db.close();
return true;
}
qDebug()<<"db failed to open! , error: "<<db.lastError().text();
return false;
More Information hopefully it would help solving this:
1- I'm using SQLITE 3
2- The problem happens when I use QSqlQuery q = db.exec("SELECT * FROM USERS"); so the DB actually opens!
3- I used two GUI programs to create the DB one of them is the latest version of SQLiteStudio which is version 3.0.4

java.sql.SQLException: Failed to start database

First, this is my first time with Apache Derby. I am using netbeans, willing to use embedded apache derby but it showing following exception
enter code here
String url="jdbc:derby:C:/Users/ankit/.netbeans-derby/kushal11";
try
{
Class.forName("org.apache.derby.jdbc.EmbeddedDriver");
con=DriverManager.getConnection(url,"APP","APP");
} catch(Exception e){ System.out.println(e);}
try {
PreparedStatement pstmt1 =
con.prepareStatement("select COUNT(*) as c from cus_details where cust_name='"+s1+"'");
ResultSet executeQuery = pstmt1.executeQuery();
int a=0;
while (executeQuery.next()){
a=executeQuery.getInt("c");
System.out.print(a);
}
But, when I am trying to insert data into the database, it is giving me the following error
enter code here
java.sql.SQLException: Failed to start database 'C:/Users/ankit/.netbeans-derby/kushal11' with class loader sun.misc.Launcher$AppClassLoader#9fef6f, see the next exception for details.
You may want to declare
Connection con = DriverManager.getConnection(url);
I don't know if you did declare it, but in your code you just have con without declaring it with Connection

Resources