| | |
Updating a MySQL database using Java
Please support our JSP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Thread Solved |
•
•
Join Date: Jan 2008
Posts: 19
Reputation:
Solved Threads: 0
I am taking a web design and development class and we have been thrown into MySQL along with java without much knowledge beforehand. Was wondering if anyone could help me with understanding how to query the database and update entries, as I am confused on how to accomplish this.
I am able to insert new entries and display table info, but when it comes to adding to existing info nothing seems to work. I can get the statement to work if I supply the data in the SQL statement i.e UPDATE tableName SET columnName1 = value1, WHERE criteria. But when I attempt to use user input and send variables along nothing seems to work.
Any help would be appreciated.
Thanks
I am able to insert new entries and display table info, but when it comes to adding to existing info nothing seems to work. I can get the statement to work if I supply the data in the SQL statement i.e UPDATE tableName SET columnName1 = value1, WHERE criteria. But when I attempt to use user input and send variables along nothing seems to work.
Any help would be appreciated.
Thanks
•
•
Join Date: Aug 2008
Posts: 1,162
Reputation:
Solved Threads: 137
Custom Application & Software Development
www.houseshark.net
www.houseshark.net
Maybe this tutorial can help you
Learn to see in another's calamity the ills which you should avoid.
Publilius Syrus
(~100 BC)
LJC - London Java Community, Graduate & Undergraduate Software Development Community, JAVAWUG (Java Web User Group), The London Android Group
Publilius Syrus
(~100 BC)
LJC - London Java Community, Graduate & Undergraduate Software Development Community, JAVAWUG (Java Web User Group), The London Android Group
•
•
Join Date: Jan 2008
Posts: 19
Reputation:
Solved Threads: 0
OK, I am still having trouble with this. All I want right now is to get something to work so I am going small. I am accessing a books database that consists of three tables, and all I want is to extract the authorID(primary key) by having the user enter the authors lastName. Currently this is what I have:
And I receive a java.sql.SQLException: Before start of result set when I try and use the method. Any suggestions would be helpful. Thanks
JSP Syntax (Toggle Plain Text)
public void AddTitle() throws SQLException { //PreparedStatement addTitle = (PreparedStatement) connection.prepareStatement //("INSERT INTO titles (title) VALUES (?) WHERE authorId FROM authorISBN = (?)"); try { PreparedStatement p = connection.prepareStatement("SELECT authorID FROM authors WHERE lastName = ?") ; String authorsFirstName, authorsLastName, newTitle, id; //authorsFirstName = GetAuthorFirstName(); authorsLastName = GetAuthorLastName(); //newTitle = GetNewTitle(); p.setString(1, authorsLastName); //p.execute(); ResultSet rs = p.executeQuery(); Integer key = rs.getInt("authorID"); //Object key = rs.(); System.out.printf("Key for author %s is %d \n", authorsLastName, key); }//end try catch(Exception exception) { exception.printStackTrace(); } }//end AddTitle method
authorsLastName, I do not see that variable passed down to AddTitle() method. If you not able to solved it, provide the whole code for this servlet
Learn to see in another's calamity the ills which you should avoid.
Publilius Syrus
(~100 BC)
LJC - London Java Community, Graduate & Undergraduate Software Development Community, JAVAWUG (Java Web User Group), The London Android Group
Publilius Syrus
(~100 BC)
LJC - London Java Community, Graduate & Undergraduate Software Development Community, JAVAWUG (Java Web User Group), The London Android Group
Uhm, Peter, what's this
;-)
However, with the way it's written (if it compiles at all) authorsLastName is an instance variable anyway (as it is not declared in the method simply defined), and that is probably not a good idea.
Otherwise, knowing exactly what SQLException you get would help. Post the rest of the message. I can almost guarantee, however, that it has to do with what GetAuthorLastName() is returning (or not).
JSP Syntax (Toggle Plain Text)
authorsLastName = GetAuthorLastName();
However, with the way it's written (if it compiles at all) authorsLastName is an instance variable anyway (as it is not declared in the method simply defined), and that is probably not a good idea.
Otherwise, knowing exactly what SQLException you get would help. Post the rest of the message. I can almost guarantee, however, that it has to do with what GetAuthorLastName() is returning (or not).
Java Programmer and Sun Systems Administrator
----------------------------------------------
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
----------------------------------------------
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
![]() |
Similar Threads
- Login Form verification MySQL "Java" (Java)
- Help me with my myspace clone (PHP)
- help with sql d/base & java gui (Java)
Other Threads in the JSP Forum
- Previous Thread: Binding Command Objects to JSP form?
- Next Thread: servlet: why the service method run twice in special time
| Thread Tools | Search this Thread |
apache array backbutton combobox comma connection csv database development directorystructure dropdownlist dynamicpagetitles eclipse frames glassfish ie8 imagetodatabse imageupload integer internet java javaee javascript jsf jsp jsppagetitles levels mvc2 mvcmodel2 mysql netbeans network parameters passing ping printinserverinsteadofclient read redirect request.getparameter response seperated servlet servletdopost()readxml sessions software sql ssl state_saving_method stocks sun tomcat tutorial update values video web write






