Showing results for 
Search instead for 
Do you mean 
If you don't find an answer, please click here to post your question.
Reply
Occasional Visitor
Posts: 1
Registered: ‎02-25-2019

POST-ing data from a RESTful web service to a Microsoft Azure Database

[ Edited ]

I have the following code to POST data to a database from a web service. I am using the RESTful web service and I am connecting to a Microsoft Azure Database. I get this error message on the server run mode ->'Resource not available". Can someone help me with this issue?

@Path("/addcar/{CSID}/{PID}/{LicensePlateNumber}/{RegistrationNumber}/{CarModel}/{MakeYear}")
@POST
@Produces(MediaType.TEXT_PLAIN)
@Consumes (MediaType.APPLICATION_FORM_URLENCODED)

public String insertdata(@PathParam("CSID") String csid,
        @PathParam("PID") String pid,
        @PathParam("LicensePlateNumber") String lpn,
        @PathParam("RegistrationNumber") String rn,
        @PathParam("CarModel") String carmodel,
        @PathParam("MakeYear") String makeyear) throws ServletException,
        IOException, SQLException, ClassNotFoundException {
        Connection conn = null;
        Statement stmt = null;
        PreparedStatement query = null;
        String myString = null;

        System.out.println(csid+ ","+ pid +","+lpn + ","+rn + ","+carmodel +","+ makeyear);

        //Car car = new Car();
        //car.newcar(csid, pid, lpn, rn, carmodel,makeyear);
           String DB_URL = "jdbc:sqlserver://nysj1rpznm.database.windows.net:1433;database=gparkdb;user=gpark@nysj1rpznm;password=Technology00000;encrypt=true;hostNameInCertificate=*.database.windows.net;loginTimeout=30;";
           String USER = "gpark";
           String PASS = GlobalUtil.PASS; 
try{
          //STEP 2: Register JDBC driver
          Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");

          //STEP 3: Open a connection
          System.out.println("Connecting to database...");
          conn = DriverManager.getConnection(DB_URL,USER,PASS);
            stmt = conn.createStatement();
            String sql = "INSERT into gpark_cars(CSID,PID,LicensePlateNumber,RegistrationNumber,CarModel,MakeYear) VALUES("+csid+""+ pid +""+ lpn+ ""+ rn+ ""+ carmodel+""+ makeyear+")";
            ResultSet rs2 = stmt.executeQuery(sql);
            System.out.println(sql);
            stmt.executeUpdate(sql);
            conn.close();
            stmt.close();
            conn.close();
}
catch(SQLException se){
    //Handle errors for JDBC
    se.printStackTrace();
 }catch(Exception e){
    //Handle errors for Class.forName
    e.printStackTrace();
 }finally{
    //finally block used to close resources
    try{
       if(stmt!=null)
          stmt.close();
    }catch(SQLException se2){
    }// nothing we can do
    try{
       if(conn!=null)
          conn.close();
    }catch(SQLException se){
       se.printStackTrace();
    }//end finally try
 }//end try
 return "Vehilce added";
 //System.out.println("Goodbye!");
}

 

Moderator
Posts: 4
Registered: ‎06-08-2017

Re: POST-ing data from a RESTful web service to a Microsoft Azure Database

Hi there,

 

Can you please confirm the expected end result of posting this data and how it is related to Ooyala?

 

Thanks,

Vikas