http://db.apache.org/derby/derby_downloads.html: db-derby-10.13.1.1-bin
http://db.apache.org/derby/releases/release-10.13.1.1.html : db-derby-10.13.1.1-bin.zip
Download: db-derby-10.13.1.1-bin.zip
Extra folder -> goto lib folder -> check "derby.jar" & " derbyclient.jar" files.
Steps: Configure derby db
1. Open Eclipse IDE "Java EE IDE"
2. Create new Java Project eg: "JDBC Project"
3. Right Click "Build Path"
4. Select "Configure Build Path"
5. goto "Libraries" tab in "Build path"
6. Add External JAR
7. Choose to folder "derby.jar"
8. Apply
// make file src/ TestConnection .java
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class TestConnection {
public static void main(String[] args) throws SQLException {
// TODO Auto-generated method stub
Connection conn = DriverManager.getConnection("jdbc:derby:D:\\Notes\\TU\\bca 6 th sem\\Java Advance Programming\\JDBCinteliJ\\db\\testdb;create=true");
System.out.println("Connected to Derby Database!");
Statement stmt = conn.createStatement();
//Creating a table in Derby database
String query;
query = "CREATE TABLE Greetings (Message CHAR(20))";
stmt.execute(query);
query = "INSERT INTO Greetings VALUES('Hello, World')";
stmt.execute(query);
// stmt.close();
System.out.println("Table created");
ResultSet rs = stmt.executeQuery("Select * from Greetings");
System.out.println("Contents of the table Greetings table:");
while(rs.next()) {
System.out.print(rs.getString("Message"));
System.out.println();
}
conn.close();
}
}
No comments:
Post a Comment