What is SQL JDBC?
JDBC (Java Database Connectivity) is the Java API that manages connecting to a database, issuing queries and commands, and handling result sets obtained from the database. Released as part of JDK 1.1 in 1997, JDBC was one of the first components developed for the Java persistence layer.
How JDBC works
Developed as an alternative to the C-based ODBC (Open Database Connectivity) API, JDBC offers a programming-level interface that handles the mechanics of Java applications communicating with a database or RDBMS. The JDBC interface consists of two layers:
- The JDBC API supports communication between the Java application and the JDBC manager.
- The JDBC driver supports communication between the JDBC manager and the database driver.
JDBC is the common API that your application code interacts with. Beneath that is the JDBC-compliant driver for the database you are using.
Using JDBC to connect to a database
One of the fortunate facts of programming in the Java ecosystem is that you will likely find a stable JDBC database connector for whatever database you choose. In this tutorial we'll use SQLite to get to know JDBC, mainly because it's so easy to use.
- Install or locate the database you want to access.
- Include the JDBC library.
- Ensure the JDBC driver you need is on your classpath.
- Use the JDBC library to obtain a connection to the database.
- Use the connection to issue SQL commands.
- Close the connection when you're finished.
A. Download File Sqljdbc4.jar (Copy File Sqljdbc4.jar to folder library)
link 2 : Download Here
B. Create File Java Connection Database with SQL Server ZK Framework (Sqljdbc4.jar)
SQLConnection.java
package com.apps.db;
import java.sql.Connection;
import java.sql.DriverManager;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.sql.DataSource;
import org.zkoss.zul.Messagebox;
public class DBSQLConnection {
public Connection openConnection(){
Connection Conn = null;
try {
Context initContext = new InitialContext();
Context envContext = (Context)initContext.lookup("java:/comp/env");
DataSource ds = (DataSource)envContext.lookup("jdbc/apps");
Conn = ds.getConnection();
}catch (Exception e) {
System.out.println("Error : " + e.getMessage());
Messagebox.show("Connection Failed..: "+e.getMessage());
}
return Conn;
}
}
-
Create File XML Connection Java With SqlServer (JDBC) :
https://qr-notes.blogspot.com/2021/08/create-file-xml-connection-java-zk.html
-
Create File Java Connection :
https://qr-notes.blogspot.com/2021/09/create-file-java-connection-database.html
- Create Form Index.zul #Part 1 Simple For Beginner : https://qr-notes.blogspot.com/2020/06/java-web-zk-framework-sql-server-tips.html
-
Create Form Login :
https://qr-notes.blogspot.com/search?q=login
- Create Form Menu Side Bar : https://qr-notes.blogspot.com/2021/05/java-web-zk-framework-sql-server-tips.html
No comments:
Post a Comment