Open Netbeans IDE and click on services tab, Right click on Java DB connect server + create new database
Right click on YourDB link and connect After creating database
Required DerbyClient jar file
You can easy download derbyclient.jar file here
How to add .jar file into your projects
Step 1 : Right click on your Project and go to the project property Step 2 : click on libraries and click on add JAR/Folder button
Java JDBC Connection Program using Derby DB
package javadb;
import java.sql.*;
public class JavaDB {
public static void main(String[] args) {
try {
Class.forName("org.apache.derby.jdbc.ClientDriver");
} catch (ClassNotFoundException e) {
System.out.println("Class not found " + e);
}
String DbURL = "jdbc:derby://localhost:1527/test";
String Uname = "root";
String Pwd = "root";
try {
Connection con = DriverManager.getConnection(DbURL, Uname, Pwd);
System.out.println("DB Connected");
con.close();
System.out.println("DB disconnected");
} catch (SQLException e) {
System.out.println("SQL exception occured" + e);
}
}
}
No comments:
Post a Comment