Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Develop a Java code (HW3.java) to get connected to the database (using JDBC) and to insert a new customer record by calling the stored procedure

 Develop a Java code (HW3.java) to get connected to the database (using JDBC) and to insert a new customer record by calling the stored procedure usp_Insert_Customer from within your Java code. ? Make sure your Java code is interactive by prompting the user to enter customer number, name, balance ant etc. ? Test your program by trying to insert new customers with 0, positive and negative balances and see if the non-zero balances are rejected. ? Acknowledge the user whether or not the insertion is gone through. Modify the following code to talk to the database import java.sql.*; import java.util.Scanner; /* * You can download MS SQL Server JDBC driver at * http://www.microsoft.com/downloads/en/details.aspx?FamilyID=a737000d-68d0-4531-b65d-da0f2a735707&displaylang=en * * Add sqljdbc4.jar to BlueJ Libraries from Preferences * * Copy sqljdbc_auth.dll to the same folder with your java file * * Refer to the following MSDN manual for more information * on connecting to SQL Server usin JDBC * http://msdn.microsoft.com/en-us/library/ms378672.aspx * */ public class ConnectDB { // Declare the JDBC objects. Connection connection = null; Statement stmt = null; ResultSet rs = null; /** * Constructor for objects of class Connect */ public ConnectDB()throws Exception { // Get connection Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver"); connection = DriverManager.getConnection("jdbc:sqlserver://CSCSQL;user=csc4355_Atay;password=CSC4355_Atay"); } public void execQuery() throws Exception{ // Create and execute an SQL statement that returns some data. Double mybalance; String sql="select CustNo, custFirstName, CustLastName,CustBal from Customer where CustBal=+mybalance"; Scanner keyboard = new Scanner(System.in); System.out.println("Please enter Balancce.: "); mybalance=keyboard.nextDouble(); stmt=connection.createStatement(); rs=stmt.executeQuery(sql); // Iterate through the data in the result set and display it. System.out.println("NO FIRSTNAME LASTNAME BALANCE"); System.out.println("=========================="); while (rs.next()) { System.out.println(rs.getString(1)+" "+rs.getString(2)+" "+rs.getString(3) +" "+rs.getDouble(4)); } } // execQuery public static void main (String args[]) throws Exception { ConnectDB con = new ConnectDB(); con.execQuery(); } } // End of Connect

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Fundamentals Of Database Systems

Authors: Ramez Elmasri, Shamkant B. Navathe

7th Edition Global Edition

1292097612, 978-1292097619

More Books

Students also viewed these Databases questions