© 2014 Firstsoft Technologies (P) Limited. login
Hi 'Guest'
Home SiteMap Contact Us Disclaimer
enggedu

Home Placements Interview Questions Java Interview Questions And Answers Java Interview Questions On JDBC Conectivity▼

Java Interview Questions On JDBC Conectivity

19. What are the different types of Statements?

Answer

  1. Statement (use createStatement method)
  2. Prepared Statement (Use prepareStatement method)
  3. Callable Statement (Use prepareCall)

20. If you want to use the percent sign (%) as the percent sign and not have it interpreted as the SQL wildcard used in SQL LIKE queries, how to do that?

Answer:

Use escape keyword. For example: stmt.executeQuery("select tax from sales where tax like '10\%' {escape '\'}");

21. How to escape ' symbol found in the input line?

Answer

You may use a method to do so:

static public String escapeLine(String s) {
  String retvalue = s;
  if (s.indexOf ("'") != -1 ) {
    StringBuffer hold = new StringBuffer();
    char c;
    for(int i=0; i < s.length(); i++ ) {
      if ((c=s.charAt(i)) == '\'' ) {
      hold.append ("''");
    }else {
     hold.append(c);
    }
  }
  retvalue = hold.toString();
  }
  return retvalue;
}
Note that such method can be extended to escape any other characters that the database driver may interprete another way.

22. How to make an update?

Answer

Creates a Statement object and calls the Statement.executeUpdate method.

String updateString = "INSERT INTO aDatabase VALUES (some text)";
int count = stmt.executeUpdate(updateString);
Previous Next
1 2 3 4 5 6 7 8
SLogix Student Projects
bottom