Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
89 views

JAVA - JDBC and VB - ADO - NET Comparison

This document compares how to connect to a database and execute queries in Java and VB.NET. It outlines the key steps: 1. Import necessary libraries and register the database driver. 2. Create a connection to the database using the driver, username, password, and URL. 3. Create a statement object to execute queries, and use it to execute a sample query and store the results in a result set. 4. Read the result set by iterating through it and accessing column values, then close the result set and statement. 5. Close the connection to the database.

Uploaded by

Thobius Joseph
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
89 views

JAVA - JDBC and VB - ADO - NET Comparison

This document compares how to connect to a database and execute queries in Java and VB.NET. It outlines the key steps: 1. Import necessary libraries and register the database driver. 2. Create a connection to the database using the driver, username, password, and URL. 3. Create a statement object to execute queries, and use it to execute a sample query and store the results in a result set. 4. Read the result set by iterating through it and accessing column values, then close the result set and statement. 5. Close the connection to the database.

Uploaded by

Thobius Joseph
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

SN JAVA VB.

NET
1. Import java.sql.*; Using System.Data.SqlClient;
2. - Load the drviver Add necessary references
- Register the Driver
Class.ForName(“com.mysql.jdbc.Driver”); OR
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
3. Create connection Instantiate the connection
Connection con = SqlConnection conn = new
DriverManager.getConnection(“URL”,”UserName”,”Psw”) SqlConnection(
"Data
Connection SQlCnn = Source=(local);Initial
DriverManager.getConnection("jdbc:sqlserver://127.0.0.1; Catalog=Northwind;Integrated
databaseName= VBDtbthoby; user= User1; password= zxc"); Security=SSPI");
4. Create statement // 2. Open the connection
Statement st = con.Createstatement(); conn.Open();

Statement MyDBstmt = SQlCnn.createStatement(); // 3. Pass the connection


ResultSet MyRSet = MyDBstmt.executeQuery("Select * From to a command object
Tbthoby"); SqlCommand cmd = new
SqlCommand("select * from
Customers", conn);
5. Reade result set. // get query results
ResultSet rs = rs.ExecuteQuery(“Select * from table”) rdr =
While (rs.next()) cmd.ExecuteReader();
{rs.getInt(1);}
// print the CustomerID
ResultSet MyRSet = MyDBstmt.executeQuery("Select * From of each record
Tbthoby"); while (rdr.Read())
while( MyRSet.next()) { {
System.out.println(MyRSet.getString("Id") + " | " +
MyRSet.getString("Name")); Console.WriteLine(rdr[0]);
} }
MyRSet.close(); }
MyDBstmt.close();
SQlCnn.close();
6. Close statement // close the reader
St.close if (rdr != null)
Close connection {
Con.Close rdr.Close();
}

// 5. Close the
connection
if (conn != null)
{
conn.Close();
}

You might also like