Search Results

Search found 2876 results on 116 pages for 'cursor'.

Page 18/116 | < Previous Page | 14 15 16 17 18 19 20 21 22 23 24 25  | Next Page >

  • Advice on software / database design to avoid using cursors when updating database

    - by Remnant
    I have a database that logs when an employee has attended a course and when they are next due to attend the course (courses tend to be annual). As an example, the following employee attended course '1' on 1st Jan 2010 and, as the course is annual, is due to attend next on the 1st Jan 2011. As today is 20th May 2010 the course status reads as 'Complete' i.e. they have done the course and do not need to do it again until next year: EmployeeID CourseID AttendanceDate DueDate Status 123456 1 01/01/2010 01/01/2011 Complete In terms of the DueDate I calculate this in SQL when I update the employee's record e.g. DueDate = AttendanceDate + CourseFrequency (I pull course frequency this from a separate table). In my web based app (asp.net mvc) I pull back this data for all employees and display it in a grid like format for HR managers to review. This allows HR to work out who needs to go on courses. The issue I have is as follows. Taking the example above, suppose today is 2nd Jan 2011. In this case, employee 123456 is now overdue for the course and I would like to set the Status to Incomplete so that the HR manager can see that they need to action this i.e. get employee on the course. I could build a trigger in the database to run overnight to update the Status field for all employees based on the current date. From what I have read I would need to use cursors to loop over each row to amend the status and this is considered bad practice / inefficient or at least something to avoid if you can??? Alternatively, I could compute the Status in my C# code after I have pulled back the data from the database and before I display it on screen. The issue with this is that the Status in the database would not necessarily match what is shown on screen which just feels plain wrong to me. Does anybody have any advice on the best practice approach to such an issue? It helps, if I did use a cursor I doubt I would be looping over more than 1000 records at any given time. Maybe this is such small volume that using cursors is okay?

    Read the article

  • Different behavior for REF CURSOR between Oracle 10g and 11g when unique index present?

    - by wweicker
    Description I have an Oracle stored procedure that has been running for 7 or so years both locally on development instances and on multiple client test and production instances running Oracle 8, then 9, then 10, and recently 11. It has worked consistently until the upgrade to Oracle 11g. Basically, the procedure opens a reference cursor, updates a table then completes. In 10g the cursor will contain the expected results but in 11g the cursor will be empty. No DML or DDL changed after the upgrade to 11g. This behavior is consistent on every 10g or 11g instance I've tried (10.2.0.3, 10.2.0.4, 11.1.0.7, 11.2.0.1 - all running on Windows). The specific code is much more complicated but to explain the issue in somewhat realistic overview: I have some data in a header table and a bunch of child tables that will be output to PDF. The header table has a boolean (NUMBER(1) where 0 is false and 1 is true) column indicating whether that data has been processed yet. The view is limited to only show rows in that have not been processed (the view also joins on some other tables, makes some inline queries and function calls, etc). So at the time when the cursor is opened, the view shows one or more rows, then after the cursor is opened an update statement runs to flip the flag in the header table, a commit is issued, then the procedure completes. On 10g, the cursor opens, it contains the row, then the update statement flips the flag and running the procedure a second time would yield no data. On 11g, the cursor never contains the row, it's as if the cursor does not open until after the update statement runs. I'm concerned that something may have changed in 11g (hopefully a setting that can be configured) that might affect other procedures and other applications. What I'd like to know is whether anyone knows why the behavior is different between the two database versions and whether the issue can be resolved without code changes. Update 1: I managed to track the issue down to a unique constraint. It seems that when the unique constraint is present in 11g the issue is reproducible 100% of the time regardless of whether I'm running the real world code against the actual objects or the following simple example. Update 2: I was able to completely eliminate the view from the equation. I have updated the simple example to show the problem exists even when querying directly against the table. Simple Example CREATE TABLE tbl1 ( col1 VARCHAR2(10), col2 NUMBER(1) ); INSERT INTO tbl1 (col1, col2) VALUES ('TEST1', 0); /* View is no longer required to demonstrate the problem CREATE OR REPLACE VIEW vw1 (col1, col2) AS SELECT col1, col2 FROM tbl1 WHERE col2 = 0; */ CREATE OR REPLACE PACKAGE pkg1 AS TYPE refWEB_CURSOR IS REF CURSOR; PROCEDURE proc1 (crs OUT refWEB_CURSOR); END pkg1; CREATE OR REPLACE PACKAGE BODY pkg1 IS PROCEDURE proc1 (crs OUT refWEB_CURSOR) IS BEGIN OPEN crs FOR SELECT col1 FROM tbl1 WHERE col1 = 'TEST1' AND col2 = 0; UPDATE tbl1 SET col2 = 1 WHERE col1 = 'TEST1'; COMMIT; END proc1; END pkg1; Anonymous Block Demo DECLARE crs1 pkg1.refWEB_CURSOR; TYPE rectype1 IS RECORD ( col1 vw1.col1%TYPE ); rec1 rectype1; BEGIN pkg1.proc1 ( crs1 ); DBMS_OUTPUT.PUT_LINE('begin first test'); LOOP FETCH crs1 INTO rec1; EXIT WHEN crs1%NOTFOUND; DBMS_OUTPUT.PUT_LINE(rec1.col1); END LOOP; DBMS_OUTPUT.PUT_LINE('end first test'); END; /* After creating this index, the problem is seen */ CREATE UNIQUE INDEX unique_col1 ON tbl1 (col1); /* Reset data to initial values */ TRUNCATE TABLE tbl1; INSERT INTO tbl1 (col1, col2) VALUES ('TEST1', 0); DECLARE crs1 pkg1.refWEB_CURSOR; TYPE rectype1 IS RECORD ( col1 vw1.col1%TYPE ); rec1 rectype1; BEGIN pkg1.proc1 ( crs1 ); DBMS_OUTPUT.PUT_LINE('begin second test'); LOOP FETCH crs1 INTO rec1; EXIT WHEN crs1%NOTFOUND; DBMS_OUTPUT.PUT_LINE(rec1.col1); END LOOP; DBMS_OUTPUT.PUT_LINE('end second test'); END; Example of what the output on 10g would be:   begin first test   TEST1   end first test   begin second test   TEST1   end second test Example of what the output on 11g would be:   begin first test   TEST1   end first test   begin second test   end second test Clarification I can't remove the COMMIT because in the real world scenario the procedure is called from a web application. When the data provider on the front end calls the procedure it will issue an implicit COMMIT when disconnecting from the database anyways. So if I remove the COMMIT in the procedure then yes, the anonymous block demo would work but the real world scenario would not because the COMMIT would still happen. Question Why is 11g behaving differently? Is there anything I can do other than re-write the code?

    Read the article

  • I get java.lang.NullPointerException when trying to get the contents of the database in Android

    - by ncountr
    I am using 8 EditText boxes from the NewCard.xml from which i am taking the values and when the save button is pressed i am storing the values into a database, in the same process of saving i am trying to get the values and present them into 8 different TextView boxes on the main.xml file and when i press the button i get an FC from the emulator and the resulting error is java.lang.NullPointerException. If Some 1 could help me that would be great, since i have never used databases and this is my first application for android and this is the only thing keepeng me to complete the whole thing and publish it on the market like a free app. Here's the full code from NewCard.java. public class NewCard extends Activity { private static String[] FROM = { _ID, FIRST_NAME, LAST_NAME, POSITION, POSTAL_ADDRESS, PHONE_NUMBER, FAX_NUMBER, MAIL_ADDRESS, WEB_ADDRESS}; private static String ORDER_BY = FIRST_NAME; private CardsData cards; EditText First_Name; EditText Last_Name; EditText Position; EditText Postal_Address; EditText Phone_Number; EditText Fax_Number; EditText Mail_Address; EditText Web_Address; Button New_Cancel; Button New_Save; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.newcard); cards = new CardsData(this); //Define the Cancel Button in NewCard Activity New_Cancel = (Button) this.findViewById(R.id.new_cancel_button); //Define the Cancel Button Activity/s New_Cancel.setOnClickListener ( new OnClickListener() { public void onClick(View arg0) { NewCancelDialog(); } } );//End of the Cancel Button Activity/s //Define the Save Button in NewCard Activity New_Save = (Button) this.findViewById(R.id.new_save_button); //Define the EditText Fields to Get Their Values Into the Database First_Name = (EditText) this.findViewById(R.id.new_first_name); Last_Name = (EditText) this.findViewById(R.id.new_last_name); Position = (EditText) this.findViewById(R.id.new_position); Postal_Address = (EditText) this.findViewById(R.id.new_postal_address); Phone_Number = (EditText) this.findViewById(R.id.new_phone_number); Fax_Number = (EditText) this.findViewById(R.id.new_fax_number); Mail_Address = (EditText) this.findViewById(R.id.new_mail_address); Web_Address = (EditText) this.findViewById(R.id.new_web_address); //Define the Save Button Activity/s New_Save.setOnClickListener ( new OnClickListener() { public void onClick(View arg0) { //Add Code For Saving The Attributes Into The Database try { addCard(First_Name.getText().toString(), Last_Name.getText().toString(), Position.getText().toString(), Postal_Address.getText().toString(), Integer.parseInt(Phone_Number.getText().toString()), Integer.parseInt(Fax_Number.getText().toString()), Mail_Address.getText().toString(), Web_Address.getText().toString()); Cursor cursor = getCard(); showCard(cursor); } finally { cards.close(); NewCard.this.finish(); } } } );//End of the Save Button Activity/s } //======================================================================================// //DATABASE FUNCTIONS private void addCard(String firstname, String lastname, String position, String postaladdress, int phonenumber, int faxnumber, String mailaddress, String webaddress) { // Insert a new record into the Events data source. // You would do something similar for delete and update. SQLiteDatabase db = cards.getWritableDatabase(); ContentValues values = new ContentValues(); values.put(FIRST_NAME, firstname); values.put(LAST_NAME, lastname); values.put(POSITION, position); values.put(POSTAL_ADDRESS, postaladdress); values.put(PHONE_NUMBER, phonenumber); values.put(FAX_NUMBER, phonenumber); values.put(MAIL_ADDRESS, mailaddress); values.put(WEB_ADDRESS, webaddress); db.insertOrThrow(TABLE_NAME, null, values); } private Cursor getCard() { // Perform a managed query. The Activity will handle closing // and re-querying the cursor when needed. SQLiteDatabase db = cards.getReadableDatabase(); Cursor cursor = db.query(TABLE_NAME, FROM, null, null, null, null, ORDER_BY); startManagingCursor(cursor); return cursor; } private void showCard(Cursor cursor) { // Stuff them all into a big string long id = 0; String firstname = null; String lastname = null; String position = null; String postaladdress = null; long phonenumber = 0; long faxnumber = 0; String mailaddress = null; String webaddress = null; while (cursor.moveToNext()) { // Could use getColumnIndexOrThrow() to get indexes id = cursor.getLong(0); firstname = cursor.getString(1); lastname = cursor.getString(2); position = cursor.getString(3); postaladdress = cursor.getString(4); phonenumber = cursor.getLong(5); faxnumber = cursor.getLong(6); mailaddress = cursor.getString(7); webaddress = cursor.getString(8); } // Display on the screen add for each textView TextView ids = (TextView) findViewById(R.id.id); TextView fn = (TextView) findViewById(R.id.firstname); TextView ln = (TextView) findViewById(R.id.lastname); TextView pos = (TextView) findViewById(R.id.position); TextView pa = (TextView) findViewById(R.id.postaladdress); TextView pn = (TextView) findViewById(R.id.phonenumber); TextView fxn = (TextView) findViewById(R.id.faxnumber); TextView ma = (TextView) findViewById(R.id.mailaddress); TextView wa = (TextView) findViewById(R.id.webaddress); ids.setText(String.valueOf(id)); fn.setText(String.valueOf(firstname)); ln.setText(String.valueOf(lastname)); pos.setText(String.valueOf(position)); pa.setText(String.valueOf(postaladdress)); pn.setText(String.valueOf(phonenumber)); fxn.setText(String.valueOf(faxnumber)); ma.setText(String.valueOf(mailaddress)); wa.setText(String.valueOf(webaddress)); } //======================================================================================// //Define the Dialog that alerts you when you press the Cancel button private void NewCancelDialog() { new AlertDialog.Builder(this) .setMessage("Are you sure you want to cancel?") .setTitle("Cancel") .setCancelable(false) .setPositiveButton("Yes", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { NewCard.this.finish(); } }) .setNegativeButton("No", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { dialog.cancel(); } }) .show(); }//End of the Cancel Dialog }

    Read the article

  • Set caret position in contenteditable div layer in Chrome/webkit

    - by Alex
    Hello, I'm trying to set the caret position in a contenteditable div layer, and after a bit of searching the web and experimenting I got it to work in firefox using this: function set(element,position){ element.focus(); var range= window.getSelection().getRangeAt(0); range.setStart(element.firstChild,position); range.setEnd(element.firstChild,position); } [...] set(document.getElementById("test"),3); But in Chrome/webkit it selects all of the content in the div. Is this a bug with webkit or am I doing something wrong? Thank you in advance.

    Read the article

  • Any suggestions on how to extract 6 million records from an oracle10g ?

    - by R K
    I just want to give you a little background Need to write a PL-SQL which will extract 6 million record joining different tables and create a file of that. Need more suggestions, specifically on how to fetch these many records. As fetching these million of records on a single go can be a highly resource intensive. So question is how to fetch these many records ? Any pl-sql will be highly appreciated.

    Read the article

  • How to set custom size for cursor in swing?

    - by swift
    I am using the below code to set a custom cursor for JPanel, but its enlarging the image which i set for cursor. Is there a way to set a customized cursor size ? Toolkit toolkit = Toolkit.getDefaultToolkit(); BufferedImage erasor=new BufferedImage(10,10, BufferedImage.TYPE_INT_RGB); Graphics2D g2d=(Graphics2D) erasor.createGraphics(); g2d.setPaint(Color.red); g2d.drawRect(e.getX(),e.getY() ,10, 10); toolkit.getBestCursorSize(10, 10); Cursor mcursor=toolkit.createCustomCursor(erasor, new Point(10,10), "Eraser"); setCursor(mcursor);

    Read the article

  • SQL Server: How to iterate over function arguments

    - by atricapilla
    I'm trying to learn SQL and for demonstration purposes I would like to create a loop which iterates over function arguments. E.g. I would like to iterate over SERVERPROPERTY function arguments (propertynames). I can do single select like this: SELECT SERVERPROPERTY('ProductVersion') AS ProductVersion, SERVERPROPERTY('ProductLevel') AS ProductLevel, SERVERPROPERTY('Edition') AS Edition, SERVERPROPERTY('EngineEdition') AS EngineEdition; GO but how to iterate over all these propertynames? Thanks in advance.

    Read the article

  • How do I create a stored procedure that calls sp_refreshview for each view in the database?

    - by Allrameest
    Today I run this select 'exec sp_refreshview N''['+table_schema+'].['+table_name+']''' from information_schema.tables where table_type = 'view' This generates a lot of: exec sp_refreshview N'[SCHEMA].[TABLE]'. I then copy the result to the query editor window and run all those execs. How do I do this all at once? I would like to have a stored procedure called something like dev.RefreshAllViews which I can execute to do this...

    Read the article

  • How to update records based on sum of a field then use the sum to calc a new value in sql

    - by Casey
    Below is what i'm trying to do with by iterating through the records. I would like to have a more elegant solution if possible since i'm sure this is not the best way to do it in sql. set @counter = 1 declare @totalhrs dec(9,3), @lastemp char(7), @othrs dec(9,3) while @counter <= @maxrecs begin if exists(select emp_num from #tt_trans where id = @counter) begin set @nhrs = 0 set @othrs = 0 select @empnum = emp_num, @nhrs = n_hrs, @othrs = ot_hrs from #tt_trans where id = @counter if @empnum = @lastemp begin set @totalhrs = @totalhrs + @nhrs if @totalhrs > 40 begin set @othrs = @othrs + @totalhrs - 40 set @nhrs = @nhrs - (@totalhrs - 40) set @totalhrs = 40 end end else begin set @totalhrs = @nhrs set @lastemp = @empnum end update #tt_trans set n_hrs = @nhrs, ot_hrs = @othrs where id = @counter and can_have_ot = 1 end set @counter = @counter + 1 end Thx

    Read the article

  • Why can't we use strong ref cursor with dynamic SQL Statement?

    - by Vineet
    Hi ALL, I am trying to use a strong ref cur with dynamic sql statment but it is giving out an error,but when i use weak cursor it works,Please explain what is the reason and please forward me any link of oracle server architect containing matter about how compilation and parsing is done in Oracle server. THIS is the error along with code. ERROR at line 6: ORA-06550: line 6, column 7: PLS-00455: cursor 'EMP_REF_CUR' cannot be used in dynamic SQL OPEN statement ORA-06550: line 6, column 2: PL/SQL: Statement ignored declare type ref_cur_type IS REF CURSOR RETURN employees%ROWTYPE; --Creating a strong REF cursor,employees is a table emp_ref_cur ref_cur_type; emp_rec employees%ROWTYPE; BEGIN OPEN emp_ref_cur FOR 'SELECT * FROM employees'; LOOP FETCH emp_ref_cur INTO emp_rec; EXIT WHEN emp_ref_cur%NOTFOUND; END lOOP; END;

    Read the article

  • How to show hand cursor when mouse is over List component?

    - by Lost_in_code
    I am aware that the follow will show a hand cursor: component.mouseChildren = true; component.useHandCursor = true; component.buttonMode = true; When I do the above on a List component, the hand button is shown and the whole component loses it's interactivity (Hand cursor is shown even on scrollbars). So how can I show the hand cursor only when rolling over the list items?

    Read the article

  • How to schedule heavy work for later display for Listviews?

    - by Pentium10
    I have a listview with 200 items. I use a custom view for each row. There is a code that takes some time to calculate, and because of this the list hangs out on scrolling and loads in slow (2-3sec). I have subclassed SimpleCursorAdapter, and using Filterable and SectionIndexer. I have in mind to show initially the name of the record, and put in a thread the calculation, and will show up later when it's done. How do I push back some work, and later update the listview to include the calculated data? This should show up on fly without user interaction.

    Read the article

  • NullPointerException while trying to bind at SimpleCursorAdapter

    - by hrskrs
    I have asked a question before where i found my mistake. However now i am facing with another problem. I have checked all the similar errors asked on StackOverflow but without success.Any help is appriciated. The idea here is that i am getting image names from DB so depending on those names images from Drawable folder will be shown in a listView together with a description but im getting an error of NullPointException at setViewValue. Here is the code snippet: private void populateListView() { ListView customListView = (ListView)findViewById(R.id.lvCustom); Cursor cursor = DBhelper.getAllimages(); startManagingCursor(cursor); String[] from = { DBhelper.COLUMN_PIC_URL, DBhelper.COLUMN_PIC_DESC}; int[] to = {R.id.ivImg, R.id.tvTitle}; SimpleCursorAdapter cursorAdapter = new SimpleCursorAdapter(this, R.layout.custom_listview_row, cursor, from, to, 0); cursorAdapter.setViewBinder(new ViewBinder() { @Override public boolean setViewValue(View view, Cursor cursor, int columnIndex) { ImageView imageImageView = (ImageView)findViewById(R.id.ivImg); String[] imgNames = new String[cursor.getCount()]; int[] imgResourceIds = new int[cursor.getCount()]; for(int i=0; i<cursor.getCount(); i++){ imgNames[i] = cursor.getString(cursor.getColumnIndex(DBhelper.COLUMN_PIC_URL)); imgResourceIds[i] = getResources().getIdentifier(imgNames[i], "drawable", getPackageName()); imageImageView.setImageResource(imgResourceIds[i]); cursor.moveToNext(); } return true; } }); customListView.setAdapter(cursorAdapter); } Here is the Error from LogCat: I have tried to log the output of imgNames[i] where it returns the url pic from the DB correctly and imgResourceIds[i] where it return the image resource id correctly also(it does not return NULL but something like: 295731). But it stops at imageImageView.setImageResource(imgResourceIds[i]); To see from where that NullPointerException is coming, i commented out imageImageView.setImageResource(imgResourceIds[i]);. This time imageNames(those with a TAG) and imgResourceIds(those system printed out) came correctly but doubled, when i removed cursor.MoveToNext() last row were doubled. Here is the screen shot of that: I have tried all the suggestions on stack about gettin a NullException but without success. Any idea where i am doing mistake?

    Read the article

  • Black screen white cursor and can't boot from live disc that I installed from just yesterday (Ubuntu 12.04)

    - by Luke
    So, I've decided to change to Ubuntu from Windows 7 after reformatting. Install goes smoothly, I've set everything up, and it works for a day. It crashed when I had a full screen video, froze, so I rebooted, and now I can't get past the black screen with flashing white underscore cursor. If I wait a while, I get "Reboot and Select proper Boot device or Insert Boot Media in selected Boot device and press any key" I've tried that, removed any boot options but the DVD drive, even tried my Windows 7 boot CD as well. Nothing boots, so I can't do anything. This is on an Asus A52N laptop, and all I can access now is the BIOS (version K52N 217), as far as I can tell.

    Read the article

  • QGraphicsView and custom Cursors

    - by Etienne de Martel
    I am trying to make use of a mix of custom cursors and preset cursors for my QGraphicsView. In my implementation we have created a notion of "modes" for the view. Meaning that depending on what "mode" the user is in, different things will happen on the left-click, or left-click drag. Anyway, none of that is the problem, just the context. The problem arises when I try to change the cursor for each mode. For instance, for mode 1 we want to show the regular Arrow cursor, but for mode 2, we want to use a custom pixmap. Seemingly simple we call graphicsview->viewport()->setCursor(Qt::QArrowCursor)  when we are switching to mode 1, and graphicsview->viewport()->setCursor(our custom cursor) for mode 2. Except it doesn't work at all. Firstly, the cursor does not change to the custom cursor. That is the first problem. However, if through another operation the drag mode of the graphics view gets set to ScrollHandDrag, the cursor will switch to the custom cursor once the drag operation is complete. Weird. But the plot thickens... Once we switch to the custom cursor, it can never be changed back to the ArrorCursor no matter how many times we call setCursor(Qt::QArrowCursor). it also doesn't seem to matter whether I call setCursor on the viewport or the graphics view itself. So, just for fun, I added a call to graphicsview->unsetCursor() just before we want to change the cursor, and that at least rectifies the second problem. The cursor changes just fine so long as we do a little HandDragging in between. Better, but certainly not optimal. However it should be noted, that doing the unsetCursor on the viewport doesn't work. it must absolutely be done on the graphicsview - regardless of the fact that we are setting the cursor on the viewport. To completely patch over the problem I have added these two lines after I set the cursor: graphicsview->setDragMode(QGraphicsView::ScrollHandDrag); graphicsview->setDragMode(QGraphicsView::NoDrag); Which works, but ye gads!! So something magical is happening inside these two methods that fixes the problem, but glancing at the code I don't see what. Something to do with the fact that the drag mode is changing the cursor I imagine. Just for completeness, I should also mention that the thing that triggers the mode change, is a QPushButton that has been added to the scene using QGraphicsScene->addWidget(). I don't know if that has anything to do with it, but you never know. I am hoping that either someone could clarify why I need to make these seemingly random calls. I don't think I am doing anything wrong anywhere. Thanks in advance for any help. EDIT: Here is an actual code example with the cursor patches as described above. You can look at and/or download them from the link below. It was a little long to paste here. I included the framework around which the cursors are changed, because I have a funny feeling that that is important somehow. https://gist.github.com/712654 The code where the problem lies is in MyGraphicsView.cpp starting at line 104. This is where the cursor is set in the graphics view. It is exactly as described above. Keep in mind, with the very ugly patches in place the cursors do work - more or less. Without those lines you will see very clearly the problems listed in the post above. Also included in the link, is all the code for a mainWindow that uses the view, etc... the only thing missing are the images I am using. But the images themselves don't matter, any 16x16 pngs will do.

    Read the article

  • How to refresh ListAdapter/ListView in android

    - by user2463990
    I have database with 2 table, custom layout for my listView, and I'm using ListAdapter to display all data on ListView - this works fine. But, I have problem when I wish display something other on listView from my Database. The data is just append on my ListView - I won't this! How I refresh/update ListAdapter? This is my MainActivity: ListAdapter adapter; protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); search = (EditText) findViewById(R.id.search); lista = (ListView) findViewById(android.R.id.list); sqlite = new Sqlite(MainActivity.this); //When apps start, listView is populated with data adapter = new SimpleAdapter(this, sqlite.getAllData(), R.layout.lv_layout, new String[]{"ime","naziv","kolicina","adresa"}, new int[]R.id.kupac,R.id.proizvod,R.id.kolicina,R.id.adresa}); setListAdapter(adapter); search.addTextChangedListener(new TextWatcher() { @Override public void onTextChanged(CharSequence s, int start, int before,int count) { // TODO Auto-generated method stub String tekst = s.toString(); ArrayList<HashMap<String, String>> rez = Sqlite.getFilterData(tekst); adapter = new SimpleAdapter(MainActivity.this, rez,R.layout.lv_layout, new String[]{"ime","naziv","kolicina","adresa"}, new int[]{R.id.kupac,R.id.proizvod,R.id.kolicina,R.id.adresa}); lista.setAdapter(adapter); } } The problem is when the method onTextChanged is called. I get all the data but the data just append to my ListView. How to fix it? And this is my Sqlite class where is needed method: ArrayList<HashMap<String,String>> results_criteria = new ArrayList<HashMap<String,String>>(); public ArrayList<HashMap<String, String>> getFilterData(String criteria) { String ime_kupca = ""; String product = ""; String adress = ""; String kolicina = ""; SQLiteDatabase myDb = this.getReadableDatabase(); Cursor cursor = myDb.rawQuery("SELECT " + DB_COLUMN_IME + "," + DB_COLUMN_NAZIV + "," + DB_COLUMN_KOLICINA + "," + DB_COLUMN_ADRESA + " FROM " + DB_TABLE1_NAME + "," + DB_TABLE2_NAME + " WHERE kupac.ID = proizvod.ID AND " + DB_COLUMN_IME + " LIKE '%" + criteria + "%'", null); if(cursor != null){ if(cursor.moveToFirst()){ do{ HashMap<String,String>map = new HashMap<String,String>(); ime_kupca = cursor.getString(cursor.getColumnIndex(DB_COLUMN_IME)); product = cursor.getString(cursor.getColumnIndex(DB_COLUMN_NAZIV)); kolicina = cursor.getString(cursor.getColumnIndex(DB_COLUMN_KOLICINA)); adress = cursor.getString(cursor.getColumnIndex(DB_COLUMN_ADRESA)); map.put("ime", ime_kupca); map.put("naziv", product); map.put("kolicina", kolicina); map.put("adresa", adress); results_criteria.add(map); }while(cursor.moveToNext()); //cursor.close(); } cursor.close(); } Log.i("Rez", "" + results_criteria); return results_criteria;

    Read the article

  • Sqlite returns error

    - by ruruma
    I'm trying to implement loading data from database and put it into different views. But log cat returns error, that it cannot find "_id" column. Can somebody help me with this? SqlHelper Code public class FiboSqlHelper extends SQLiteOpenHelper { public static final String TABLE_FILMDB = "FiboFilmTop250"; public static final String COLUMN_ID = "_id"; private static final String DATABASE_NAME = "FiboFilmDb250.sqlite"; private static final int DATABASE_VERSION = 1; public static final String COLUMN_TITLE = "Title"; public static final String COLUMN_RATING = "Rating"; public static final String COLUMN_GENRE = "Genre"; public static final String COLUMN_TIME = "Time"; public static final String COLUMN_PREMDATE = "PremDate"; public static final String COLUMN_PLOT = "Plot"; private static final String DATABASE_CREATE = "create table "+TABLE_FILMDB+"("+COLUMN_ID +" integer primary key autoincrement, " +COLUMN_TITLE+" text not null "+COLUMN_RATING+" text not null "+COLUMN_GENRE+" text not null "+COLUMN_TIME+" text not null "+COLUMN_PREMDATE+" text not null "+COLUMN_PLOT+" "+"text not null)"; public FiboSqlHelper(Context context) { super(context, DATABASE_NAME, null, DATABASE_VERSION); // TODO Auto-generated constructor stub } @Override public void onCreate(SQLiteDatabase db) { // TODO Auto-generated method stub db.execSQL(DATABASE_CREATE); } @Override public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { // TODO Auto-generated method stub Log.w(FiboSqlHelper.class.getName(), "Upgrading database from version " + oldVersion + " to " + newVersion + ", which will destroy all old data"); db.execSQL("DROP TABLE IF EXISTS " + TABLE_FILMDB); onCreate(db); } }` SqlAdapterCode: public class FiboSqlAdapter { private SQLiteDatabase database; private FiboSqlHelper dbHelper; private String[] allColumns = {FiboSqlHelper.COLUMN_ID, FiboSqlHelper.COLUMN_TITLE, FiboSqlHelper.COLUMN_GENRE, FiboSqlHelper.COLUMN_PREMDATE, FiboSqlHelper.COLUMN_TIME, FiboSqlHelper.COLUMN_PLOT}; public FiboSqlAdapter (Context context){ dbHelper = new FiboSqlHelper(context); } public void open() throws SQLException { database = dbHelper.getWritableDatabase(); } public void close(){ dbHelper.close(); } public List<FilmDataEntity> getAllFilmData(){ List<FilmDataEntity> fDatas = new ArrayList<FilmDataEntity>(); Cursor cursor = database.query(FiboSqlHelper.TABLE_FILMDB, allColumns, null,null,null,null,null); cursor.moveToFirst(); while(!cursor.isAfterLast()){ FilmDataEntity fData = cursorToData(cursor); fDatas.add(fData); cursor.moveToNext(); } cursor.close(); return fDatas; } private FilmDataEntity cursorToData(Cursor cursor){ FilmDataEntity fData = new FilmDataEntity(); fData.setId(cursor.getLong(1)); fData.setTitle(cursor.getString(2)); fData.setRating(cursor.getString(6)); fData.setGenre(cursor.getString(4)); fData.setPremDate(cursor.getString(5)); fData.setShortcut(cursor.getString(8)); return fData; }} DataEntity: ` public class FilmDataEntity { private long id; private String title; private String rating; private String genre; private String premDate; private String shortcut; public String getShortcut() { return shortcut; } public void setShortcut(String shortcut) { this.shortcut = shortcut; } public String getGenre() { return genre; } public void setGenre(String genre) { this.genre = genre; } public String getPremDate() { return premDate; } public void setPremDate(String premDate) { this.premDate = premDate; } public String getTitle() { return title; } public void setTitle(String title) { this.title = title; } public String getRating() { return rating; } public void setRating(String rating) { this.rating = rating; } public long getId() { return id; } public void setId(long id) { this.id = id; } } Part from main activity: `List<FilmDataEntity> fE1; sqA = new FiboSqlAdapter(this); sqA.open(); fE1 = sqA.getAllFilmData(); `

    Read the article

  • Android: NullPointerException error in getting data in database

    - by Gil Viernes Marcelo
    This what happens in the system. 1. Admin login this is in other activity but i will not post it coz it has nothing to do with this (no problem) 2. Register user in system (using database no problem) 3. Click add user button (where existing user who register must display its name in ListView) Problem: When I click adduser to see if the system registered the user, it force close. CurrentUser.java package com.example.istronggyminstructor; import java.util.ArrayList; import android.os.Bundle; import android.app.Activity; import android.content.Context; import android.content.Intent; import android.database.Cursor; import android.view.Gravity; import android.view.LayoutInflater; import android.view.Menu; import android.view.View; import android.view.View.OnClickListener; import android.view.ViewGroup; import android.view.ViewGroup.LayoutParams; import android.view.WindowManager; import android.widget.ArrayAdapter; import android.widget.Button; import android.widget.EditText; import android.widget.FrameLayout; import android.widget.ListView; import android.widget.PopupWindow; import android.widget.TextView; import android.widget.Toast; import java.util.ArrayList; import java.util.List; import java.util.Random; import com.example.istronggyminstructor.registeredUserList.Users; import android.content.ContentValues; import android.database.Cursor; import android.database.SQLException; import android.database.sqlite.SQLiteDatabase; public class CurrentUsers extends Activity { private Button register; private Button adduser; EditText getusertext, getpass, getweight, textdisp; View popupview, popupview2; public static ArrayList<String> ArrayofName = new ArrayList<String>(); protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_current_users); register = (Button) findViewById(R.id.regbut); adduser = (Button) findViewById(R.id.addbut); register.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { LayoutInflater inflator = (LayoutInflater) getBaseContext() .getSystemService(LAYOUT_INFLATER_SERVICE); popupview = inflator.inflate(R.layout.popup, null); final PopupWindow popupWindow = new PopupWindow(popupview, LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); popupWindow.showAtLocation(popupview, Gravity.CENTER, 0, 0); popupWindow.setFocusable(true); popupWindow.update(); Button dismissbtn = (Button) popupview.findViewById(R.id.close); dismissbtn.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { popupWindow.dismiss(); } }); popupWindow.showAsDropDown(register, 50, -30); } }); //Thread.setDefaultUncaughtExceptionHandler(new forceclose(this)); } public void registerUser(View v) { EditText username = (EditText) popupview.findViewById(R.id.usertext); EditText password = (EditText) popupview .findViewById(R.id.passwordtext); EditText weight = (EditText) popupview.findViewById(R.id.weight); String getUsername = username.getText().toString(); String getPassword = password.getText().toString(); String getWeight = weight.getText().toString(); dataHandler dbHandler = new dataHandler(this, null, null, 1); Users user = new Users(getUsername, getPassword, Integer.parseInt(getWeight)); dbHandler.addUsers(user); Toast.makeText(getApplicationContext(), "Registering...", Toast.LENGTH_SHORT).show(); } public void onClick_addUser(View v) { LayoutInflater inflator = (LayoutInflater) getBaseContext() .getSystemService(LAYOUT_INFLATER_SERVICE); popupview2 = inflator.inflate(R.layout.popup2, null); final PopupWindow popupWindow = new PopupWindow(popupview2, LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); popupWindow.showAtLocation(popupview2, Gravity.CENTER, 0, -10); popupWindow.setFocusable(true); popupWindow.update(); Button dismissbtn = (Button) popupview2.findViewById(R.id.close2); dismissbtn.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { popupWindow.dismiss(); } }); popupWindow.showAsDropDown(register, 50, -30); dataHandler dbHandler = new dataHandler(this, null, null, 1); dbHandler.getAllUsers(); ListView list = (ListView)findViewById(R.layout.popup2); ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, ArrayofName); list.setAdapter(adapter); } @Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.current_users, menu); return true; } } registeredUserList.java package com.example.istronggyminstructor; public class registeredUserList { public static class Users { private static int _id; private static String _users; private static String _password; private static int _weight; private static String[] _workoutlists; private static int _score; public Users() { } public Users(String username, String password, int weight) { _users = username; _password = password; _weight = weight; } public int getId() { return _id; } public static void setId(int id) { _id = id; } public String getUsers() { return _users; } public static void setUsers(String users) { _users = users; } public String getPassword(){ return _password; } public void setPassword(String password){ _password = password; } public int getWeight(){ return _weight; } public static void setWeight(int weight){ _weight = weight; } public String[] getWorkoutLists(){ return _workoutlists; } public void setWorkoutLists(String[] workoutlists){ _workoutlists = workoutlists; } public int score(){ return _score; } public void score(int score){ _score = score; } } } dataHandler.java package com.example.istronggyminstructor; import java.util.ArrayList; import java.util.List; import com.example.istronggyminstructor.registeredUserList.Users; import android.content.ContentValues; import android.content.Context; import android.database.Cursor; import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteDatabase.CursorFactory; import android.database.sqlite.SQLiteOpenHelper; public class dataHandler extends SQLiteOpenHelper { private static final int DATABASE_VERSION = 1; private static final String DATABASE_NAME = "userInfo.db"; public static final String TABLE_USERINFO = "user"; public static final String COLUMN_ID = "_id"; public static final String COLUMN_USERNAME = "username"; public static final String COLUMN_PASSWORD = "password"; public static final String COLUMN_WEIGHT = "weight"; public dataHandler(Context context, String name, CursorFactory factory, int version) { super(context, DATABASE_NAME, factory, DATABASE_VERSION); } @Override public void onCreate(SQLiteDatabase db) { String CREATE_USER_TABLE = "CREATE TABLE " + TABLE_USERINFO + " (" + COLUMN_ID + " INTEGER PRIMARY KEY, " + COLUMN_USERNAME + " TEXT," + COLUMN_PASSWORD + " TEXT, " + COLUMN_WEIGHT + " INTEGER " + ");"; db.execSQL(CREATE_USER_TABLE); } @Override public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { db.execSQL("DROP TABLE IF EXISTS " + TABLE_USERINFO); onCreate(db); } public void addUsers(Users user) { ContentValues values = new ContentValues(); values.put(COLUMN_USERNAME, user.getUsers()); values.put(COLUMN_PASSWORD, user.getPassword()); values.put(COLUMN_WEIGHT, user.getWeight()); SQLiteDatabase db = this.getWritableDatabase(); db.insert(TABLE_USERINFO, null, values); db.close(); } public Users findUsers(String username) { String query = "Select * FROM " + TABLE_USERINFO + " WHERE " + COLUMN_USERNAME + " = \"" + username + "\""; SQLiteDatabase db = this.getWritableDatabase(); Cursor cursor = db.rawQuery(query, null); Users user = new Users(); if (cursor.moveToFirst()) { cursor.moveToFirst(); Users.setUsers(cursor.getString(1)); //Users.setWeight(Integer.parseInt(cursor.getString(3))); not yet needed cursor.close(); } else { user = null; } db.close(); return user; } public List<Users> getAllUsers(){ List<Users> user = new ArrayList(); String selectQuery = "SELECT * FROM " + TABLE_USERINFO; SQLiteDatabase db = this.getWritableDatabase(); Cursor cursor = db.rawQuery(selectQuery, null); if (cursor.moveToFirst()) { do { Users users = new Users(); users.setUsers(cursor.getString(1)); String name = cursor.getString(1); CurrentUsers.ArrayofName.add(name); // Adding contact to list user.add(users); } while (cursor.moveToNext()); } // return user list return user; } public boolean deleteUsers(String username) { boolean result = false; String query = "Select * FROM " + TABLE_USERINFO + " WHERE " + COLUMN_USERNAME + " = \"" + username + "\""; SQLiteDatabase db = this.getWritableDatabase(); Cursor cursor = db.rawQuery(query, null); Users user = new Users(); if (cursor.moveToFirst()) { Users.setId(Integer.parseInt(cursor.getString(0))); db.delete(TABLE_USERINFO, COLUMN_ID + " = ?", new String[] { String.valueOf(user.getId()) }); cursor.close(); result = true; } db.close(); return result; } } Logcat 08-20 03:23:23.293: E/AndroidRuntime(16363): FATAL EXCEPTION: main 08-20 03:23:23.293: E/AndroidRuntime(16363): java.lang.IllegalStateException: Could not execute method of the activity 08-20 03:23:23.293: E/AndroidRuntime(16363): at android.view.View$1.onClick(View.java:3599) 08-20 03:23:23.293: E/AndroidRuntime(16363): at android.view.View.performClick(View.java:4204) 08-20 03:23:23.293: E/AndroidRuntime(16363): at android.view.View$PerformClick.run(View.java:17355) 08-20 03:23:23.293: E/AndroidRuntime(16363): at android.os.Handler.handleCallback(Handler.java:725) 08-20 03:23:23.293: E/AndroidRuntime(16363): at android.os.Handler.dispatchMessage(Handler.java:92) 08-20 03:23:23.293: E/AndroidRuntime(16363): at android.os.Looper.loop(Looper.java:137) 08-20 03:23:23.293: E/AndroidRuntime(16363): at android.app.ActivityThread.main(ActivityThread.java:5041) 08-20 03:23:23.293: E/AndroidRuntime(16363): at java.lang.reflect.Method.invokeNative(Native Method) 08-20 03:23:23.293: E/AndroidRuntime(16363): at java.lang.reflect.Method.invoke(Method.java:511) 08-20 03:23:23.293: E/AndroidRuntime(16363): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793) 08-20 03:23:23.293: E/AndroidRuntime(16363): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560) 08-20 03:23:23.293: E/AndroidRuntime(16363): at dalvik.system.NativeStart.main(Native Method) 08-20 03:23:23.293: E/AndroidRuntime(16363): Caused by: java.lang.reflect.InvocationTargetException 08-20 03:23:23.293: E/AndroidRuntime(16363): at java.lang.reflect.Method.invokeNative(Native Method) 08-20 03:23:23.293: E/AndroidRuntime(16363): at java.lang.reflect.Method.invoke(Method.java:511) 08-20 03:23:23.293: E/AndroidRuntime(16363): at android.view.View$1.onClick(View.java:3594) 08-20 03:23:23.293: E/AndroidRuntime(16363): ... 11 more 08-20 03:23:23.293: E/AndroidRuntime(16363): Caused by: java.lang.NullPointerException 08-20 03:23:23.293: E/AndroidRuntime(16363): at com.example.istronggyminstructor.CurrentUsers.onClick_addUser(CurrentUsers.java:118) 08-20 03:23:23.293: E/AndroidRuntime(16363): ... 14 more

    Read the article

  • Approaches to replace cursor in pure AS3 / Flare project?

    - by peteorpeter
    Hi there good lookin, I've got a pure AS3 (no Flex) project that uses Flare to display and interact with a data visualization. I just implemented some panning behavior, so you can click and drag the visualization around, and now I'd like to give the user a visual indicator that this is possible, by switching the arrow cursor with a nice grabby-looking hand icon. The user can click and drag at any time except when the mouse is over a clickable node (at which time the cursor swaps to a pointer - this behavior is already in place). So... 1) Do I need to create my own custom bitmap/sprite or is there a palette of built-in cursors I can use? (I'm not using Flex.) 2) Is there a way to simply replace the default arrow with the pan cursor project-wide, or do I need to attach the swapping to mouse events on display objects? Can I use the stage object to make this behavior apply everywhere? 3) How do I perform the swap? Do I use the Cursor object directly or do I need to get involved with the CursorManager? Any guidance, pseudo-code, or words of wisdom is greatly appreciated!

    Read the article

  • Unable to boot into 11.10 in normal (get a black screen) OR recovery (get just a flashing cursor, no cli)

    - by user1092284
    Okay, so I had a dual boot of Tango Studio (based on Ubuntu 10.04) and Windows XP. Yesterday I downloaded the .iso for Ubuntu 11.10 and attempted to install from a USB (my BIOS won't normally boot from USB but I had PLOP boot manager on a CD). I booted up Ubuntu from the USB and then from there formatted the partition with Tango on and installed Ubuntu 11.10. On booting up I came into Grub rescue mode. So I booted up from the USB again and used boot-repair to reinstall Grub. After this I would see the normal Grub menu, but on choosing Ubuntu I would come to a black screen. On choosing recovery mode it would begin starting normally with no obvious errors but instead of coming to a cli I would just get a blank screen with a flashing cursor on the top left, not accepting any input. I have since reformatted and reinstalled from a CD rather than USB and had the exact same problem. I used boot-repair again and the result is the same. Output of the most recent boot-repair is at http://paste.ubuntu.com/869805/ I have also tried editing the ubuntu grub entry and replacing quiet with text nomodeset as I saw in an answer to another question. This got me a bit further - I saw the purple ubuntu loading screen but still came to a blank screen after that. Anyway, in most of the other questions in which that is brought up the user is still able to boot into recovery, while I am not. Can anyone help? Thanks in advance, let me know if there's any more info I need to provide! EDIT FOR MORE INFO: I read something saying it's quiet splash that should be replaced with nomodeset. Earlier I had left splash in the line. So i tried it this way and it froze after displaying the following text: fsck from util-linux 2.19.1 mountall: Plymouth command failed mountall: Disconnected from Plymouth /dev/sda5:clean, 139359/1741488 files, 745830/6961125 blocks From a bit of googling it doesn't look like plymouth is essential, but I've checked and I do have the most current versions of mountall and plymouth installed so I don't know why there's a problem EDIT FOR MORE INFO AGAIN: I used dkpg --reconfigure plymouth cause I saw it mentioned in another forum and it still says plymouth command failed on boot

    Read the article

< Previous Page | 14 15 16 17 18 19 20 21 22 23 24 25  | Next Page >