Struts DB query execution error - struts

I am trying to insert a data to my db2 9.7 database from IBM RAD 7.5 using struts 1.3
But when I execute the query I got this errors: http://pastebin.com/3UPTVKbh
KayitBean kayit=(KayitBean)form;
//String name = kayit.getName();
String name="endee";
DBConn hb = new DBConn();
Connection conn =hb.getConnection();
System.out.println("basarili");
//String sql = "SELECT * FROM ENDER.\"MEKANDENEME\"";
String sql = "INSERT INTO ENDER.\"MEKANDENEME\" VALUES (\'endere\' ,\'bos\');";
System.out.println(sql);
System.out.println("basarili2");
PreparedStatement ps = conn.prepareStatement(sql);
System.out.println("basarili3");
ResultSet rs = ps.executeQuery();
// String ender=rs.getArray(1).toString();
System.out.println("basarili4");
// System.out.println(rs);
conn.close();
I am receiving this after System.out.println("basarili3");"
Please help me.

This has nothing to do (apparently) with DB, just with Struts (please correct the title),and the code posted seems irrelevant.
Googling for "The path of an ForwardConfig cannot be null", you'll find this.
Check your Struts configuration, and discover if you are using validation or not.

I found my problem. My problem was a simple wrong bracket before forward. But it was interesting that i was getting exception always while executing the query.

Related

How to execute SQL query in ASP.NET MVC?

How to use this query in ASP.NET MVC to copy data from table and send it to another table?
INSERT INTO tblFee (AdmissionFee, Tuitionfee)
SELECT AdmissionFee, TuitionFee
FROM tblFee
Basically, you need a simple SqlConnection and SqlCommand to execute this query.
Done properly, it would look something like this:
string connectionString = "......"; // typically, you get this from a config file
string query = "INSERT INTO dbo.tblFee (AdmissionFee, Tuitionfee) SELECT AdmissionFee, TuitionFee FROM dbo.tblFee;";
// set up your connection and command, in "using" blocks
using (SqlConnection conn = new SqlConnection(connectionString))
using (SqlCommand cmdInsert = new SqlCommand(conn, query))
{
// open connection, execute query, close connection
conn.Open();
// since you are doing an "INSERT" - use "ExecuteNonQuery"
// this returns only the number of rows inserted - no result set
int rowsInserted = cmdInsert.ExecuteNonQuery();
conn.Close();
}
But with this, you're really just duplicating every row that's already in dbo.tblFee and re-inserting them back into the same table .... is that really what you're looking for??

How to insert special character in text area in C# & ASP.NET MVC?

I want to insert special characters in textarea of my ASP.NET MVC project but it cannot insert - I get an error
Syntax error near this 't
Please help me find a solution so I can complete my project as soon as possible.
It is highly recommended to use parameterized SQL when handling input from untrusted source. It not only fixes the special character problem but also prevents SQL Injection Attack:
using (MySqlCommand cmd = new MySqlCommand("insert into table_name(username)values(#username)", conn))
{
cmd.Parameters.AddWithValue("#username", username);
cmd.ExecuteNonQuery();
}
The error is coming from SQL syntax, not from C# . You add the ' it two times in a row to avoid the error
select 'test's' error
select 'test''s' runs

Trouble establishing connection to Local SQL database

Simply trying to find out the correct syntax for my connection string. Before anyone asks, yes I did look at other SO answers, and no they did not work for me. Here a couple of attempts I made from looking at other SO questions like the one I am asking
Server=(local);Database=SalesOrdersExample;Integrated Security= true
Data Source=(local);Database=SalesOrdersExample;Integrated Security=SSPI
Server=.\\SQLEXPRESS;Database=SalesOrdersExampleDataSet;Integrated Security=true
None of them worked (I have a Console.WriteLine("test"); thrown in there and it works up until I try conn.Open() (opening the connection to database) so I'm assuming that it must be my connection string since nothing gets written after conn.Open())
Console.WriteLine("test"); // works
SqlConnection conn = new SqlConnection("Server=.\\SQLEXPRESS;Database=SalesOrdersExampleDataSet;Integrated Security=true");
Console.WriteLine("test"); // works
conn.Open();
Console.WriteLine("test"); // does not work
So some information about the database is that it's local under my 'Data Connections' in my Server Explorer. I also have the .xsd file in my project so I have linked the Data Set to the current project I am on. Here is a picture representation to confirm that I have both the Data Connection and the Data Set.
EDIT: SO does not allow me to post pictures until I have 10 rep so here is direct link to picture:
DB Screenshot
Any help is appreciated thank you.
Visual Studio comes with LocalDB database, which is not exactly SQL Server Express database.
Try something like this:
Server=(localdb)\v11.0;Integrated Security=true;
or
Data Source=(LocalDB)\v11.0; AttachDbFileName=|DataDirectory|\DatabaseFileName.mdf; InitialCatalog=DatabaseName;Integrated Security=True;MultipleActiveResultSets=True
If using in c# code, you can use # to avoid problems with backslash characters:
SqlConnection conn =
new SqlConnection(#"Server=(localdb)\v11.0;Integrated Security=true;");

Failure to create a SQL Azure login with SMO

The following piece of code works with regular SQL and SMO. I'm trying to get it to work with SQL Azure. According to this MSDN article, a limited subset of functionality that I need (database and login creation) should be supported. All the business checking whether an object exists will also fail: server.Logins[loginName] != null or server.Databases.Contains(dbName). I can create a database if I dont check whether it exists or not, but i cant create a login. Anyone else ran into the same problem?
string connectionString =
"Server=tcp:XXXXXX.database.windows.net;Database=MyDatabase;User ID=XXXXXXX;Password=XXXXXX;Trusted_Connection=False;Encrypt=True;TrustServerCertificate=true;"
using (SqlConnection connection = new SqlConnection(connectionString))
{
connection.Open();
ServerConnection serverConnection = new ServerConnection(connection);
Server server = new Server(serverConnection);
Login login = new Login(server, "NewLogin");
login.LoginType = LoginType.SqlLogin;
login.Create("NewStrongPwd123***");
}
Create failed for Login 'NewLogin'.
at Microsoft.SqlServer.Management.Smo.SqlSmoObject.CreateImpl()
at Microsoft.SqlServer.Management.Smo.Login.Create(SecureString password)
at Microsoft.SqlServer.Management.Smo.Login.Create(String password)
Proposed answers to this question were identified on the MSDN Forum including a working approach. Please take a look at: http://social.msdn.microsoft.com/Forums/en-US/ssdsgetstarted/thread/26e42082-e649-4cde-916d-c1da2275e377

ADODB strange behavior

Recently I had a very strange problem.
The application is written in classic ASP, but I guess it is the same case for every connection that uses ADO/OLEDB.
Those are connection parameters.
conn=Server.CreateObject("ADODB.Connection");
conn.Provider="Microsoft.Jet.OLEDB.4.0";
conn.Open("D:/db/testingDb.mdb");
In short this code:
conn.Open("myconnection");
bigQuery = "...";
rs = conn.execute(bigQuery);
while (!rs.eof) {
...
smallQuery = "..."
rssmall = conn.execute(smallQuery);
...
rssmall.close();
...
rs.movenext();
}
rs.close();
conn.close();
Doesn't work if bigQuery returns more than certain number of rows (in my case ~20).
But if I use one more connection for inner loop like stealthyninja suggested:
conn.Open("myconnection");
conn2.Open("myconnection")
bigQuery = "...";
rs = conn.execute(bigQuery);
while (!rs.eof) {
...
smallQuery = "..."
rssmall = conn2.execute(smallQuery);
...
rssmall.close();
...
rs.movenext();
}
rs.close();
conn2.close();
conn.close();
Problem vanishes.
I am using Access database and IIS7 if that matters.
Does anyone has a logical explanation for this?
Michael Todd's comment has it. ADODB doesn't support MARS (Multiple Active Result Sets) which is what you are trying to do. The reason it seems to work with only 20 records is because that's how much it is initially transmitting to the client-side.
Standard solutions to this are
Retrieve the whole outer rowset into a holding structure or cache first, then process it and execute the inner queries, or
Use two different connections, as you have demonstrated.