String link = "http://hosted.ap.org";
I want to find whether the given url is already existing in the SQL DB under the table name “urls”. If the given url is not found in that table i need to insert it in to that table.
As I am a beginner in Java, I cannot really reach the exact code.
Please advise on this regard on how to search the url in the table.
I am done with the SQL Connection using the java code. Please advise me on the searching and inserting part alone as explained above.
You need to distinguish between two completely separate things: SQL (Structured Query Language) is the language which you use to communicate with the DB. JDBC (Java DataBase Connectivity) is a Java API which enables you to execute SQL language using Java code.
To get data from DB, you usually use the SQL
SELECTstatement. To insert data in a DB, you usually use the SQLINSERT INTOstatementTo prepare a SQL statement in Java, you usually use
Connection#prepareStatement(). To execute a SQLSELECTstatement in Java, you should usePreparedStatement#executeQuery(). It returns aResultSetwith the query results. To execute a SQLINSERTstatement in Java, you should usePreparedStatement#executeUpdate().See also: