Home arrow Java arrow Page 2 - Working with DML and DDL using NetBeans IDE
SEARCH DEVARTICLES

TOOLS YOU CAN USE

advertisement
Working with DML and DDL using NetBeans IDE - How to work with “PreparedStatement” in Java using NetBeans IDE: source code
(Page 2 of 4 )

Once you have completed all the steps in the previous section, you need to copy the following code into your button “actionperformed” event:

private void btnConnectActionPerformed(java.awt.event.ActionEvent
evt) {                                        

// TODO add your handling code here:
        try {
           Class.forName
("com.microsoft.jdbc.sqlserver.SQLServerDriver");
            Connection conn = DriverManager.getConnection
("jdbc:microsoft:sqlserver://serverjag:1433","sa","");
            PreparedStatement stmt = conn.prepareStatement
("UPDATE Northwind..emp " +
                        "SET sal = ? " +
                        "WHERE empno = ?");
            stmt.setInt(1, 5000);
            stmt.setInt(2, 1002);
            stmt.executeUpdate( );
            //stmt.clearParameters( );
            //conn.commit( );
            conn.close();
            this.txtMsg.setText("updated successfully");
        }
        catch(Exception e) {
            this.txtMsg.setText("Error: Please view Stack
Trace");
            e.printStackTrace();
        }
    }
                                          

Please be aware that you need to modify the driver and connection information according to your requirements.  You can press F5 to execute your application.  Once it completes successfully, you must see that a new text file exists named “query1.lst” with exactly the same information you find in the table.

If you receive any errors in connecting to Microsoft SQL Server, please refer to my first article in this series.

The next section will explain the above code.


blog comments powered by Disqus
JAVA ARTICLES

- Deploying Multiple Java Applets as One
- Deploying Java Applets
- Understanding Deployment Frameworks
- Database Programming in Java Using JDBC
- Extension Interfaces and SAX
- Entities, Handlers and SAX
- Advanced SAX
- Conversions and Java Print Streams
- Formatters and Java Print Streams
- Java Print Streams
- Wildcards, Arrays, and Generics in Java
- Wildcards and Generic Methods in Java
- Finishing the Project: Java Web Development ...
- Generics and Limitations in Java
- Getting Started with Java Web Development in...

Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 
Support 



© 2003-2012 by Developer Shed. All rights reserved. DS Cluster 9 - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials