Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within Java in General
Search Coderanch
Advance search
Google search
Register / Login
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Campbell Ritchie
Jeanne Boyarsky
Ron McLeod
Paul Clapham
Liutauras Vilda
Sheriffs:
paul wheaton
Rob Spoor
Devaka Cooray
Saloon Keepers:
Stephan van Hulst
Tim Holloway
Carey Brown
Frits Walraven
Tim Moores
Bartenders:
Mikalai Zaikin
Forum:
Java in General
How to update column values in the table?
jack Stanry
Greenhorn
Posts: 2
posted 8 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Please, I have problem in this code where it is update the all column values with the same last one .
public class dbconnection { java.sql.Connection con; java.sql.Statement st; ResultSet rs; public EncBean getConnection()throws SQLException{ EncBean encBean1 = new EncBean(); String v_url= "jdbc:oracle:thin:@192.168.2.138:1522:orcl2"; String v_username= "scott"; String v_password = "tiger"; try { DriverManager.registerDriver(new oracle.jdbc.OracleDriver()); con = DriverManager.getConnection(v_url,v_username,v_password); System.out.println ("Connection to Oracle database was Established"); } catch ( SQLException e) { e.printStackTrace(); } return encBean1; } public EncBean selectRows() { EncBean encBean2 = new EncBean(); try { String SQLselect="select JOB_NAME from job"; st=con.createStatement(); rs=st.executeQuery(SQLselect); while (rs.next()) { encBean2.setName(rs.getString("JOB_NAME")); } } catch ( Exception ex ) { ex.printStackTrace(); } return encBean2; } public void updateRows(String updatedname){ try { Statement stmt = con.createStatement(ResultSet.TYPE_FORWARD_ONLY,ResultSet.CONCUR_UPDATABLE); ResultSet srs = stmt.executeQuery("select job_name from job " ); while (srs.next()) { srs.updateString("job_name", updatedname); srs.updateRow(); con.commit();} System.out.println("An existing user was updated successfully!");} catch(SQLException err){ System.out.println(err.getMessage()); }}} public class mainenc { public static void main(String[] args) throws Exception{ dbconnection dbcon = new dbconnection(); EncBean encbeancon= dbcon.getConnection(); EncBean encBean5 = dbcon.selectRows(); enc concatinputs = new enc(); EncBean encBeanconcat = concatinputs.funconcat(encBean5.getName()); EncBean encBean4 = concatinputs.inputencryption(encBeanconcat.getConcatenatedData()); String vReserverbin= encBean4.getReversedBinary(); String ascistring= concatinputs.convertBinaryStringToString(vReserverbin); dbcon.updateRows(ascistring); }}
Dave Tolls
Rancher
Posts: 4801
50
posted 8 years ago
1
Number of slices to send:
Optional 'thank-you' note:
Send
What do you see and what do you expect to see?
At the moment your
updateRows
method sets the job_name column on every row to the value of '
updatename
'.
Don't get me started about those stupid
light bulbs
.
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
prepared statement problem + special character or something else
another array problem
ResultSet.TYPE_FORWARD_ONLY usage
joptionpane paramater (using a class that extends JFrame as a parameter)
Database connection problem in JSP application
More...