Presentation is loading. Please wait.

Presentation is loading. Please wait.

JDBC. JDBC (Java Database Connectivity): JDBC is an API for the Java programming language that defines how a client may access a database. It provides.

Similar presentations


Presentation on theme: "JDBC. JDBC (Java Database Connectivity): JDBC is an API for the Java programming language that defines how a client may access a database. It provides."— Presentation transcript:

1 JDBC

2 JDBC (Java Database Connectivity): JDBC is an API for the Java programming language that defines how a client may access a database. It provides methods for querying and updating data in a database.

3 How to connect Java to SQL Server?

4 Step 1 Extract the JDBC in the C:\ Driver

5 Step 2 Copy the file sqljdbc.jar from C:\Microsoft SQL Server 2005 JDBC Driver\sqljdbc_1.0\enu to C:\Program Files\Java\jdk1.6.0_20\jre\lib\ext Copy the file sqljdbc_xa.dll from C:\Microsoft SQL Server 2005 JDBC Driver\sqljdbc_1.0\enu\xa\x86 to C:\Program Files\Java\jdk1.6.0_20\jre\lib\ext

6 Step 3: Configuring NetBeans Add the JDBC jar library to NetBeans Environment: ◦ Click the tools menu choose the Java platforms then choose the source tab and add the JDBC jar library. Or you can add it to one of your application: ◦ Right click on the application and choose the properties and then choose libraries then add the JDBC jar library.

7 Step 4: Configuring SQL sever Click start >> Microsoft Sql server >> Configuration tools >> Sql server configuration manager.

8 Step 4 (continued)

9

10

11 Connection to Database Connect to sql server. Class.forName("com.microsoft.sqlserver.jdbc.SQLServer Driver"); Connect to the database DriverManager.getConnection ("jdbc:sqlserver://localhost\\SQLEXPRESS; database=master; user= sa; password=123456"); Connect to the database server Database instance name Database nameUser name to connect to Password for user sa

12 DML using Java public void dml(String x) { try { stmt.executeUpdate(x); } catch(SQLException sqle) { System.err.println(sqle); } To execute insert, update, delete statement Instance of the Statement (To execute any sql statement)

13 Select using Java public ResultSet select(String x) { try { ResultSet r=stmt.executeQuery(x); return r; } catch(SQLException sqle) { System.err.println(sqle); return null; } To execute select statement using Java To retrieve the result of the select statement

14 Methods to retrieve rows r.next(): to let the cursor points to next row. r.getString(index) r.getString(column name): to retrieve a column using index or column name


Download ppt "JDBC. JDBC (Java Database Connectivity): JDBC is an API for the Java programming language that defines how a client may access a database. It provides."

Similar presentations


Ads by Google