Statement 2 « Statement « Java Database Q&A





1. who will call..Statement.excuteQuery() method.    coderanch.com

This is a very common question, and knowing the answer should open up a whole world of understanding for you. If you look at java.sql.*, almost everything is an interface. Who implements all of these interfaces? The JDBC driver! You know how you have to load a JDBC driver before you do anything else (typically with Class.forName()?) Well, that class that ...

2. SQL statement question    coderanch.com

Hi there, I don't know if this is the right place, but I hope so. I am using Access as a database and trying to execute a sql statement but without success. The tables I have are: Candidates ---------- cand_num (PK) firstName lastName profession phone mobile email fileName Studies ------------- study_id (PK) name CandStudy ------------ cand_num (PK) study_id (PK) so they ...

3. Empty catch statement in JDBC code    coderanch.com

In general (probably universally), it is bad practice to have empty catch blocks. But what do you think of the empty catch statements in the finally block of the below code? If this is bad design, what's the best way to do it without writing 10 lines of wrapper code around 3 lines of real JDBC statement. Connection c = null; ...

4. Externalizing SQL statements in JEE    coderanch.com

Hanna, It's a matter of personal preference. I find it useful to put things that might change, like the schema name, in a property file. If the queries are highly static, it could make sense to put them in a property file. I tend to do more dynamic queries and like them closer to the code. Also, if I change the ...

5. commit statement    coderanch.com

6. Search on name using LIKE statement    coderanch.com

Hello, I have a search textfield on my website and want to be able to search on peoples firstname and lastname stored in the database. I have a database record for firstname and one for lastname. If I type in the name 'Peter Anderson' and use a SQL statement like the below: SELECT * FROM customer WHERE firstname LIKE '%firstname%' OR ...

7. executeBatch of Statement --- jdbc    coderanch.com

hi all, I am writing one jdbc program ( using mysql) in which i am executing the 4 statements , using executeBatch() method of Statement . 2 insert queries --- insert two new records 1 update query ----- update a field in a row 1 delete query ----- delete a row based on some field. here in delete query i am ...

9. JDBC statements    coderanch.com





10. memory impact on statement    coderanch.com

Hi , I am getting outofmemory exception in a webpage.In the related java class i have used Statement to retrieve the data from DB (oracle). does usage of prepared statement and statement makes any impact on memory? If i presume there is memory problem. But this exceptions occurs only at particular page rest of the things are working fine. and i ...

11. Sending a list of SQL Statements to the Server (out of the java program)    coderanch.com

Hello everybody I just wrote a small tool which dynamicly produces a list of SQL statements with respect to a few often changing attributes: (short abstract) USE DatabaseName GO IF EXISTS(select name from master.dbo.sysdatabases WHERE name = 'Database') DROP DATABASE Database; IF NOT EXISTS ( SELECT 1 FROM information_schema.columns WHERE column_name = 'Total' AND table_name = 'Table' ) BEGIN ALTER TABLE ...

13. Missing Return Statement    coderanch.com

Please I will really appreciate if anyone could point to me what I am doing wrong here. I have been on this for 72 hours now without much success and have reached the point where I need someone to give a hint on my mistake. I keep getting this error of "Missing Return Statement" even though I have a return statement. ...

14. JDBC Statements    coderanch.com

The inheritance hierarchy for JDBC statements puzzles me a little. Specifically, why would PreparedStatement and CallableStatement want to inherit some of the methods of Statement? For example, I tried the following: Connection con = ...; PreparedStatement ps = con.prepareStatement("SELECT * FROM TheTable"); ps.executeQuery("SELECT * FROM TheOtherTable"); // execute a Statement method I tried code similar to the above with MS SQL ...

15. Statement Reuse?    coderanch.com

I would like to know if we can reuse the same Statement object for executing more than one query. Or, should we create a new statement for different queries. For example, Connection con = getDBConnection(); Statement st1 = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY); int i = st1.executeUpdate("update tbl_domu set domU_status=1 where domU_id=" + dom_U_id); Statement st2 = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY); String date = new SimpleDateFormat("yyyy-MM-dd ...

16. basic sql statement doubt    coderanch.com

I have another set of column which is bit tricky for me to formulate the sql statements. Hence kindly help. The column data: num6-FG-R0001 num2-FG-R0003 num1-FG-R0040 num2-BN-R0039 num3-FG-R0090 num1-BN-R0049 num3-FG-R0002 num2-FG-R0089 num4-CD-R0001 num4-KL-R0067 num5-FG-R0056 num6-HI-R0023 num2-FG-R0003 For example num6-HI-R0023 can be constructed using 2 variables from the user and the middle part can be any 2 letters but all the columns ...





17. purpose of using statement.getGeneratedKeys    coderanch.com

when going through forums in velocity reviews i came across this : The thing I want to know is, how do I find out what the new value of an autonumber field is when I add a new record? and one of them answered as "Well, getGeneratedKeys() is "the" way to do it". Please what is the purpose of getGeneratedKeys() from ...

18. problem with sql statement in my setValueAt method    coderanch.com

functional requirement for the user to be able to edit a cell in the JTable JTable gets its data from mysql database and I am able to view the data from the database with no problem I use the setValueAt() method in my tablemodel to update the database public void setValueAt(Object value, int row, int column) { ((String[]) ResultSets.get(row)) [column] = ...

19. Complex SQL Statements    coderanch.com

20. Sql statement    coderanch.com

Hi All.. I have been struggling with this code for 3 hours now,can you please help.this code is hard coded and i need to unhard code it,so here is the code please help. select staticdata.descr as deptname,appraisal.state as appraisalPhase,appraisal.lastupdated,appraisal.scoreunitid from appraisal left JOIN hruser on hruser.userid = appraisal.appraisee LEFT JOIN staticdata on staticdata.id = hruser.deptname where appraisal.lastupdated > "1999/01/01" AND appraisal.lastupdated ...

21. Sum function sql statement    coderanch.com

22. Jdbc statement    coderanch.com

23. JDBC Statements    coderanch.com

24. is this statement correct    coderanch.com

26. UnsupportedOperationException Statement.getGeneratedKeys()    coderanch.com

Hi guys I am trying to retrieve the auto_incremented value from a MySQL Insert Statement, And I keep getting the following exception: java.lang.UnsupportedOperationException at sun.jdbc.odbc.JdbcOdbcStatement.getGeneratedKeys(JdbcOdbcStatement.java:1460) at dc3_stock_server.MyImplementation.update(MyImplementation.java:31) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:305) at sun.rmi.transport.Transport$1.run(Transport.java:159) at java.security.AccessController.doPrivileged(Native Method) .... I have googled and googled and so far no fix, have tried prepared statements as well as ...

27. statement.executeUpdate() hangs    coderanch.com

Hi, i am using a simple piece of code to update a single row in Oracle DB, the query updates just a single row but still the execution hangs on stmt.executeUpdate(). it does not throw any exception, but the control just hangs there.. I am lost here as the same piece of code worked fine earlier. try { DriverManager.registerDriver (new oracle.jdbc.driver.OracleDriver()); ...

28. How can you tune SQL statements    coderanch.com

29. Change of statements!    coderanch.com

Manjit, Welcome to JavaRanch! If you close the connection first, the statement and result set are invalid. They may or may not get closed depending on your driver. They may or may not throw an exception when you try to close them; also depending on your driver. I advise you not to code that way as the results can be unpredictable. ...

30. parse a multi-line SQL programs to get the single-line SQL statements    coderanch.com

Please help to write a program to parse a multi-line SQL programs to get the single-line SQL statements enclosed inside "jdbcTemplate.update". Input is: jdbcTemplate.update("CREATE TABLE assets ( " + "ID int not NULL auto_increment primary key, " + "Name varchar(50) default NULL, " + "Description varchar(150) default NULL, " + "isEnabled smallint default NULL, " + "ID varchar(30) default NULL, " ...

31. SQL statements in files in jars - best practice suggestions?    coderanch.com

I have a project that contains many DAOs, and therefore many SQL statements. I want to extract the SQL from related DAO's and put them in a common file. However... the project is composed of many jars (they represent modules of the main application). For example, one of the jars I create is called AudioUtils.jar. Within AudioUtils.jar are a variety of ...

32. JDBC Statement    coderanch.com

Hi , I'm unable to connect to the MySQL db, below is the code : /* * To change this template, choose Tools | Templates * and open the template in the editor. */ package javaapplication2; /** * * @author Pramod */import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.Statement; public class Main { /** * @param args the command line arguments ...

33. Statement.executeQuery fails --RESOLVED--    coderanch.com

Oh God. Thank you God. I solved the problem by enclosing the column name in quotation marks "SELECT * FROM document WHERE 'reassign_documents_primary_key_col'=2". IT IS AN UNBELIEVABLE MYSTERY. In the code below, the line ResultSet result = statement.executeQuery(selectStatement); is throwing an SQL exception : "java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver] Too few parameters. Expected 1." public CachedRowSetImpl getObjectsRowSet(String selectStatement) throws ORMException { ...

34. Empty database when using for statement    coderanch.com

Hi, i'm new to java and am trying to build a database program about boats which needs to output a .csv file. I have it all working except for one issue. It runs fine as shown below and, as expected, only outputs the first record. When i 'uncomment' the for statement it gives the error 'no data found' at line 205 ...

35. Need a conditional Statement    coderanch.com

Hi...another stupid problem i am facing here. Please help... In my servlet the DB2 Connection is perfectly working, the SQL statement is also nice. I just want to implement a condision in such way so that: if (any condition comes true) then it will print the table column as well as table data, or else it will say "Table name: No ...

36. Need help tuning a sql statement (SOLVED)    coderanch.com

Hey there, So I have the following SELECT: SELECT l.pn, l.iid, l.quantity, la.duration, la.uom, l.pid, l.rqlid FROM nrql l, pn_attributes la WHERE l.rqid = 1234 AND la.code (+) = 'QT' AND la.app_lid (+) = l.rqlid AND l.ltype = 'REG' AND l.plid IS NULL I have need of some new data, so I have added the following to get what I need ...

37. dynamically transforming conditional statements to SQL    dbforums.com

hi all I am building an application where the user enters a conditional statement and then i want to perform some action. Eg user input > if customer.name = sandro then send email My program will read the user input and then dynamically constructs an sql statement to retrieve the required info... if the sql returns data i.e. the condition succeeds, ...

38. How can a sql statement be parsed in Java?    dbforums.com

I have a sql statement which Can execute in Sql*plus and Java but, although I can execute the statement in Java when I call the method: resultSet.next() it throw sqlException and said: no statement parse... I want to ask how a statement can be parsed? is that it should NOT end with ';' in Java (In sql*plus, we end a statement ...

39. SQL statement - Invalid cursor state    dbforums.com

i am connecting to a MS Access DB, i am able to execute all the other select statments, except this one (presumably due to the SUM(Amount) as Total. SELECT invoice_type, SUM(Amount) as Total FROM invoice WHERE invoice_date >= #1 April 2004# AND invoice_date < #1 April 2005# AND Student_ID = 31 GROUP BY invoice_type I get an "Invalid Cursor State". The ...

40. statement null pointer exception    java-forums.org

41. How To Use This Statement In My Program    java-forums.org

42. need help in sql statement    java-forums.org

43. If Statement in SQL    java-forums.org

If Statement in SQL I am having to fix another developes code who left and I am consused as to how to do so... here is the issue He gets the employee id from the Report Menu table. Right now a bunch of users have the same employee id because they are contractors. He grabs the login id from ...

44. How to call set of sql statements in java?    java-forums.org

45. SQL statement doesn't work....    java-forums.org

46. SQL not runnings after if statement    java-forums.org

Can you post that code in code tags? There's a # button that'll do it. That aside, I would bet that your concatenation of strings for your query is causing an error. Since you don't log any possible SQLExceptions thrown you are not seeing that problem. You should at the very least do a printStackTrace() on the exception. As for the ...

48. Something Wrong With My SQL Statement    java-forums.org

49. SQL Display statement    java-forums.org

Exception in thread "AWT-EventQueue-0" java.lang.RuntimeException: java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver] Too few parameters. Expected 1. at Scorekeeper.menuItem8ActionPerformed(Scorekeeper.java:151) at Scorekeeper.access$000(Scorekeeper.java:10) at Scorekeeper$1.actionPerformed(Scorekeeper.java:203) at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2015) at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2338) at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:402) at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:259) at javax.swing.AbstractButton.doClick(AbstractButton.java:376) at javax.swing.plaf.basic.BasicMenuItemUI.doClick(BasicMenuItemUI.java:833) at javax.swing.plaf.basic.BasicMenuItemUI$Handler.mouseReleased(BasicMenuItemUI.java:877) at java.awt.AWTEventMulticaster.mouseReleased(AWTEventMulticaster.java:289) at java.awt.Component.processMouseEvent(Component.java:6434) at javax.swing.JComponent.processMouseEvent(JComponent.java:3321) at java.awt.Component.processEvent(Component.java:6199) at java.awt.Container.processEvent(Container.java:2203) at java.awt.Component.dispatchEventImpl(Component.java:4790) at java.awt.Container.dispatchEventImpl(Container.java:2261) at java.awt.Component.dispatchEvent(Component.java:4616) at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4803) at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4463) at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4393) at java.awt.Container.dispatchEventImpl(Container.java:2247) at java.awt.Window.dispatchEventImpl(Window.java:2674) ...

51. jdbc - sql statement    forums.oracle.com

I have an update query which is not executing and giving me result as 0 UPDATE employee SET fullname = ?,cellphone = ?,homephone = ?,otherphone = ?,gender = ?,permaddr = ?,resaddr = ?,dob = ?,doj = ?,resignationgivenon = ?,lastworkingday = ?, modifiedby = ?, modifiedat = ?,publicdesig = ?,personalemail = ?, employmenttype = ? WHERE intranetid = ?; Params: [Shantanoo Kirtane, ...

52. Sql statement help    forums.oracle.com

When i create the table without quoting, the table is being created succesfuly(the insert statement doesnt succeed like i said before). But if i do it with quotes it gives errors, and cant even create the table. duffymo, i think its possible to set multiple values. and do you mean i have to write your code in sql or in java? ...

53. how to store data into database by reading sql statements from text file    forums.oracle.com

Step 1: Create a property file to add various queries. Step 2: Read the properties file using ResourceBundle Step 3: Use the jdbc to execute the query read from the property file. So in future if you need to change query no need do any modifications in java program. But depends on how you use the property file.

54. SQL statement problem    forums.oracle.com

55. sql statements    forums.oracle.com

56. java.sql.Statement hangs    forums.oracle.com

Println("1 pre select"); Execute("select ..."); Println("2 post select"); Println("3 pre insert select"); Execute("insert ... Select ..."); Println("4 post insert select"); The app prints 1, 2, and 3, but hangs on the second execute and never gets to 4. No exception, no stack trace. It doesn't terminate. It just sits there. The pseudo might be a little rough.. I sent this from ...

57. REGEX help needed - parsing complex SQL statements    forums.oracle.com

It's not a question of elegance, it just can't be done. Regexes are not capable of matching recursive patterns like nested parentheses. If you know exactly how the query is structured, you can create a regex that explicitly matches every parenthesis. If you know the maximum depth to which the parentheses can be nested, you can write a very long, unreadable ...

58. To get execution time of sql statement    forums.oracle.com

Hi, Say you have a table named temp and you have a query like, select * from temp; now to know execution time for this query then you will need to write on your oracle prompt like set timing on select * from temp; will give you time taken by the query execution. Thanks!!!

59. JDBC Call with prepare statement    forums.oracle.com

60. Read csv file using sql statement    forums.oracle.com

62. How to detect an SQL statement execution?    forums.oracle.com

I'm building an application where once there is any change or modification for example, a DELETE statement to the database, my program will detect it and automatically runs another program to send out message. How do I detect the changes to my database using Java and automatically runs another program that sends out message? Please help. Your responds are very much ...

64. SQL Statements && Special Chars    forums.oracle.com

mezler wrote: I provided a technically correct solution. The need of escaping depends on the data to store. The usage of clobs and blobs is a question of database and driver. SQL injection was not of any interest here. What do you want kajbj? A correct answer. 1) A developer should always care about SQL injection, epsecially when loading dynamic data. ...

65. regular expression for recognizing all tables in a sql statement    forums.oracle.com

SELECT A.X, B.Y FROM A INNER JOIN B ON A.T=B.T WHERE A='2' AND B=2 this style except for the fact that i do not know previosly how many columns i have, how many inner join i have, how many and or clause i have, how many tables i have. Thanks in advance for your attention

66. sql input statement, how can i input the character " ' "(apostrophe)?    forums.oracle.com

Sorry if any inconvenience for the year old thread, but I regularly search the forum archives for answers to problems and many of the threads I end up looking have no answers that solve my problem. So when I finally get the clues I add a reply for other people to see what i found. I had a pretty hard time ...

67. SQL statements:help    forums.oracle.com

//Archive data progTxt.append("\n\n"); progTxt.append(" Archiving Data...\n "); stmt.execute("select * into outfile 'c:/emticket " + dateFormat.format(date) + ".csv' fields terminated by ',' enclosed by '\"' lines terminated by ' n' from emticket where RcvDateTime between date_sub(curdate(),interval 90 day) and curdate()"); stmt.execute("select * into outfile 'c:/emattachment " + dateFormat.format(date) + ".csv' fields terminated by ',' enclosed by '\"' lines terminated by ' n' ...

68. Adding a db record using Statement    forums.oracle.com