Menu

[Solved]Issues Making Connection Jdbc Tries Paths Didn T Seem Work Downloaded Derby File Used Derb Q37215970

Having issues making the connection with the JDBC tries a fewpaths that didn’t seem to work I downloaded the derby file and usedthe derby jar file for the path here is my code below doingsomething wrong :

The purpose of this application is to create a simple userinterface on top of a relational database. The you should use isthe Java DB (Derby) database.  Setup of the Java DB(Derby) database is covered in section 24.5.  The userinterface will allow a user to insert, delete, and update namesfrom a table in the database.

            Formore information on the Java DB (Derby) database, visit thatproject’s website at https://db.apache.org/derby/.  Fromthis website you can download Derby – getting the JDBC driver JARfile, derby.jar, you need to create and connect to a Java DB(Derby) database – and have full access to the Derby manual whichhas information on creating databases, tables, and running INSERT,UPDATE, SELECT, and DELETE SQL statements.)

The database table will look like this:

ID

FIRST_NAME

LAST_NAME

1452962065165       

Rita                           

Red                           

1452962067770       

Oscar                          

Orange                        

1452962070010       

Yet                            

The ID value is generated by the application automatically. Aneasy way to generate this value is to useSystem.currentTimeMillis();. The first name (required) and lastname (optional) are entered by the user.

import java.sql.Connection;

import java.sql.DriverManager;

import java.sql.PreparedStatement;

import java.sql.ResultSet;

import java.sql.SQLException;

import java.util.LinkedList;

import java.util.List;

public class Handler {

protected Connection conn;

  

public Handler() throwsSQLException {

conn = DriverManager.getConnection(

  

);

}

  

public void insert(Name name)throws SQLException {

Long id = System.currentTimeMillis();

String sql =

” insert into names (id, first_name, last_name) “

+ ” values “

+ ” (?, ?, ?) “

;

PreparedStatement stmt

= conn.prepareStatement(sql);

  

stmt.setLong(1, id);

stmt.setString(2, name.getFirst());

stmt.setString(3, name.getLast());

  

stmt.executeUpdate();

stmt.close();

  

name.setId(id);

}

Expert Answer


Answer to Having issues making the connection with the JDBC tries a few paths that didn’t seem to work I downloaded the derby file… . . .

OR


Leave a Reply

Your email address will not be published. Required fields are marked *