Skip to Main Content

Cloud Platform

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

How to validate path variable/Uri parameter

OTVianJan 31 2017 — edited Feb 17 2017

Hi ,
I have a Custom Api with method as GET , passing the parameter along with the url . Could you please suggest a method to check whether the parameter is null or not ?

Below given my code .

service.get('/mobile/custom/****/deviceVersion/:deviceType',function(req,res){
            
var reqParams = req.params;
            
var finalResponse;
            
var params='/'+reqParams.deviceType;
            
if(reqParams.deviceType=='{}'){   // ***Here is my problem***
                 finalResponse
= jbuilder.encode(function (json) {
                      json
.set('Response', function (json) {
                      json
.set('responseCode', '400');
                      json
.set('responseMessage', 'Malformed request query');
                 
});
           
});
            res
.status(400).send(finalResponse);
            res
.end();
           
}else{
        var connector='/deviceVersion';
       commonHandler
.CommonHandlerGetMethodFunction(req,res,connector,params);
  
}

});

I have tried the following

1. if(reqParams.deviceType=='{}'){}

2. if(JSON.Stringify(reqParams.deviceType)=='{}'){}

3. if(JSON.Stringify(reqParams.deviceType).length==0){}

Also is there anyway to debug the code other than using console?

The error that i am getting is

{
  
"type": "w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.4.1",
  
"status": 404,
  
"title": "API not found",
  
"detail": "We cannot find the API ******/1.0 for the provided URL path /deviceVersion/. Verify your request parameters and try again.",
  
"o:ecid": "005Hp2YhoPF3j4C_nDs1yZ000Uba00001w, 0:3",
  
"o:errorCode": "MOBILE-57945",
  
"o:errorPath": "/mobile/custom/******/deviceVersion/"
}

@"Tware-Oracle" , @"Chris Muir-Oracle" could you please help me with this ?

This post has been answered by User_HWHT9 on Feb 14 2017
Jump to Answer

Comments

843854
Hi I am curious to see how you established a JDBC connection using Java to SQL Server 2000.

Can you provide some code as an example for me?

I am having problems just establishing a connection. I downloaded the JDBC driver from MS site and installed it.

Here is some code I got:
--------------------------------------------------------------------------------
Connection con = DriverManager.getConnection("jdbc:microsoft:sqlserver://DEV01:1433;DatabaseName=NG_RFQ;SelectMethod=cursor", "jla", "jla");

Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery("SELECT * FROM Customer");

if(rs.next()){

customerName = rs.getString("CustomerName");
buyerName = rs.getString("BuyerName");

}

con.close();
---------------------------------------------------------------------------------------

Can you tell me what I am doing wrong? Do I need to create a new DSN or something? I have no idea.

Please advise.
Thanks!!!
843854
Hi,
I did not use MS SQL Server JDBC driver, because it has lots of bugs. So I prefer you to use MS ODBC driver, it is better.

for driver "sun.jdbc.odbc.JdbcOdbcDriver"
for url "jdbc:odbc:CCSData" CCSData is the name ODBC data source created by you
for userid "user" you will define user id and password when creating ODBC connection.
for password "user"

Goodluck
843854
Try using java.type string, for SQL server nvarchar.
Also you will have to prefix the strings with national 'N' prefix for regular statements.

Here is a sample

driver="sun.jdbc.odbc.JdbcOdbcDriver";
CURL="jdbc:odbc:database";
un=null;
pw=null;

Connection con = DriverManager.getConnection( CURL, un, pw );
Statement stmt = con.createStatement();
String insrt="INSERT INTO myTable (myCol) VALUES (N' Here is the national text ' )";
stmt.execute(insrt);

I hope this solves your problem.
625957
I did not use MS SQL Server JDBC driver, because it
has lots of bugs. So I prefer you to use MS ODBC
driver, it is better.
I have found the microsoft jdbc driver SP3 version to be pretty solid.
I would not recommend the JDBC / ODBC bridge, actually neither do Sun:
"The JDBC-ODBC Bridge driver is recommended only for experimental use or when no other alternative is available. " - http://java.sun.com/j2se/1.3/docs/guide/jdbc/getstart/bridge.doc.html





625957
Assuming you are using the microsoft driver:

The documentation says that both VARCHAR and NVARCHAR map to varchar in JDBC. No problems as all Strings are unicode in java.

Basically if you use PreparedStatements the driver adds the N before the quotes for you. Just make sure you dont set the SendStringParameters connection property to false.
1 - 5