How to update already inserted data in servlet based web application and java - servlets

I Want to make a "Employee Project Management" web application using java and java servlet pages for by which user insert details of employee and assign it a project if not assigned or update the same if already assigned.
I am stuck in a situation where I am not able to update the data in database.
suggestions and solutions will be appreciated.
Thank You.

Just like a normal database query, write in ".java" file:
PreparedStatement stmt=con.prepareStatement
("update emp set name=?,id=?, project=? where id=?");
stmt.setString(1, name);
stmt.setString(2, id);
stmt.setString(3, project);
stmt.setString(4, id);
stmt.executeUpdate();

Related

Truncate table via web service

Hi does anybody know if its possible to truncate a staging table via a web service in AX 2012? There is the delete method, however this is a bit slow for a large number of records.
For anyone who is struggling with this. I created a new method (class and operation) in my web service and exposed this, to delete all records from a table. The following code was used:
[SysEntryPointAttribute(true)]
public void truncateTable()
{
TableNameHere tableNameHere;
;
ttsBegin;
delete_from tableNameHere;
ttsCommit;
}
As I don't have any details about your web service (is that customization of some standard service or you've created custom service?), I'd like to suggest following: create Custom web service with one method which will delete required records.

FoxPro Database and asp.net

I have a website that uses asp.net 3.5 and Sql server 2008 as backend data store . now we want to add a new page to our website . but the data that we want to share in this page is already being created and saved by a FoxPro software in one of our local systems.
I've no experience in FoxPro . is there any way to use this data in our site ? specially without being have to create a new database in server and importing or writing all records all over again ? what is the best way in such a situation ?
by the way , is it possible to change the extension of a FoxPro database or not ? something like Database.customExt ?
You can connect to a FoxPro database using an OLEDB datasource in ADO.NET. It's up to you whether you feel the need to import the data into SQL Server or just access it directly in FoxPro. It would depend on whether you want to join the data with the SQL Server data in queries for one thing.
In addition to the answers that you already got. You might be interested in using LINQ to VFP or VFP Entity Framwork Provider to make the data access even easier by using LINQ.
You could create a linked server to this Foxpro Database.
Also, Foxpro tables can have any extension. However, you'll have to specify the extension when using the table or database. For Example:
OPEN DATABASE MyFoxProDatabase.customExt
USE mytable.custonExt
You have several options for structuring your data access to FoxPro. You can put the ADO.NET data access code in the codebehind, in it's own c# library or use the objectdatasource for 2 way binding.
private void LoadData(string parameter)
{
string sql = "SELECT a.myfield FROM mytable.customExt a WHERE a.whereField=?";
using(OleDbConnection conn = new OleDbConnection(myConnectionString))
{
using (OleDbCommand command = new OleDbCommand(sql, conn))
{
command.Parameters.AddWithValue("#Parameter", parameter);
try
{
conn.Open();
using(OleDbDataReader dr = command.ExecuteReader(CommandBehavior.CloseConnection))
{
myGridView.DataSource = dr;
myGridView.DataBind();
}
}
catch (Exception ex)
{
throw;
}
}
}
}
Here is a sample connection string to use in web.config:
<add name="myData" connectionString="Provider=VFPOLEDB.1;Data Source=C:\MyFiles\" providerName="System.Data.OleDb"/>
I belive ou can use a custom extension to your FoxPro tables and databases. All your SQL statements would then need to explicitly use that extension.
SELECT t.MyField FROM MyTable.customExt t
While you can change the extension for a Visual FoxPro table, that only affects the DBF file. If the table has any memo fields, there's an associated FPT file, for which you can't change the extension. Similarly, if the table has an associated index file, it must have a CDX extension.
So, if the reason you want to change the extension is to allow multiple tables with the same filestem, don't. It's a good way to really mess things up.

"Invalid object name" after restoring SQL Server 2008 database

I'm switching my web host and backed up my database. Due to some restriction with my new host I could not restore the .bak file and had to send to them so they would restore it. Once they had restored it, I ran my application I get this
System.Data.SqlClient.SqlException: Invalid object name "<table name>"
whenever I try to query a table from the application. However, I have no problems logging in through management studio with same user name and password and querying the tables.
I'm running a mvc 3 site with SQL Server 2008
Does anyone know why I might getting these exceptions when trying to run my application?
EDIT:
Some more information:
the user name I was using in my old db was Kimpo54321 so all tables I had created got prefixed like this Kimpo54321. so I tried adding it to the very first query in my web app so it would be SELECT * FROM Kimpo54321.<tablename> and the query passed without the exception.
Now I did not have to prefix each table name with this earlier in my application and I don't want to apply it to all my queries. Is there a way to fix this?
EDIT:
I ran this to get a alter schema line for each table and changed everything to dbo and its finally working. thnx aaron for pointing me in the right direction finding the answer
SELECT 'ALTER SCHEMA dbo TRANSFER ' + s.Name + '.' + o.Name
FROM sys.Objects o
INNER JOIN sys.Schemas s on o.schema_id = s.schema_id
WHERE s.Name = 'yourschema'
And (o.Type = 'U' Or o.Type = 'P' Or o.Type = 'V')
Are you referencing the schema (e.g. dbo.table vs. table)? It is possible that your user at the new host has a different default schema than at your old host. How are you "querying the tables" - right-clicking and selecting one of the options, or using the exact same query issued by the application?
This is likely an issue where the Web App's user needs to be re-added to the restored database. Certain users do not maintain their permissions when a database is restored onto a different sql server.

Retrieving Data from the Database ASP.NET MVC + Oracle

I have two tables
Users (Userid, Name, PhoneNumber)
Applications (ApplicationsId,UserId, ApplicationName, ActiveDate)
Every user will have more than 1 application.
In Nhibernate using lazy loading I can get the users data along with all the applications for every user. So, I used to do something like user.applications[i].Applicationname to get all the applications.
But, Now how do i retrieve all the applications along with the users data using oracle commands. I know how to get one application using joins. But, how do i retrieve multiple applications and store it in a IList. Any help is greatly appreciated. Thank you.
First you should download the Oracle Data Provider for .NET in
http://www.oracle.com/technology/tech/windows/odpnet/index.html
after you make sure that you can open a connection to your oracle database then
define mapping file of your entities in Nhibernate and map table columns of your oracle table to .NET object. after that you can use the following code snippet to get the list of your entity from database
// create the query...
IQuery query = session.CreateQuery( "from Post p where p.Blog.Author = :author" );
// set the parameters...
query.SetString("author", (String) instance);
// fetch the results...
IList results = query.List();
You should define the (Post) entity and (Blog) entity to your mapping file and as you can see (Post) has relation to (Blog) entity which is defined in the mapping file too.

ASP.NET LINQ to SQL SubmitChanges() doesn't update the database

In my 2nd ASP.NET MVC project I'm facing a very weird problem: when I call the SubmitChanges method of the DataContext class, nothing updates in the database. It's weird because everything works fine with my first project.
I'm using a remote database created in Sql Server Management Studio, I tried doing some queries there and in Visual Studio 2010 (where I have the connection to the database), they all work.
Where might the problem be hidden?
DBDataContext DB = new DBDataContext();
var myuser = DB.Users.Single(u => u.ID == id);
myuser.Age = 45;
DB.SubmitChanges();
SOLUTION
This is embarrassing :D Indeed I didn't have a primary key. Now it works!
Thanks to everybody!
Table , KEY :)::):)
Insert KEY in TABLE !!!!!
Maybe there isn't anything to submit to the database? SubmitChanges() only will submit modified or new data, if you don't have either, then it will no have any persitent effect.
You may want to read ScottGu's series on Linq to understand a bit more about Linq, or could want to by a book like Linq in action.
Is it possible that the entities you are modifying are not connected to the DataContext? This would prevent them from causing updates to your database.
I'd check your connection string. You might not be connecting to the database you think you're connecting to.

Resources