Reputation: 1591
im a novice programmer and i wanna know what is the basic way to connect a java program to Derby in netbeans 7.2.1. my prof asked me to make a program that lets me add, delete, save, search and edit entries from a table. i already know how to make a GUI java program in netbeans and how to make a database on netbeans too. i just want to know what are the basic codes to include in a program to enable it to connect on a database on netbeans 7.2.1. thank you for your time reading my question.
public void connection(){
try{
Class.forName("org.apache.derby.jdbc.ClientDriver");
String myDb = "jdbc:derby://localhost:1527/HWtrial";
Connection DBconn = DriverManager.getConnection(myDb, "","");
s1 = DBconn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
result = s1.executeQuery("SELECT * from HWSTUD");
result.next();
result.last();
}catch(Exception ex){
JOptionPane.showMessageDialog(null,"Cannot Connect to Database", "Error Message", JOptionPane.OK_OPTION);
};
}
Upvotes: 1
Views: 13054
Reputation: 1
Class.forName("org.apache.derby.jdbc.ClientDriver");
String myDb = "jdbc:derby://localhost:1527/HWtrial";
Connection DBconn = DriverManager.getConnection(myDb, "","");
Statement st=DBconn.createStatement();
ResultSet rs=st.executeQuery("select * from student");
while(rs.next)
{
out.println(rs.getString(1));
}|
Upvotes: 0
Reputation: 16339
The Derby documentation contains an excellent set of tutorials to help you get started: http://db.apache.org/derby/docs/10.9/getstart/
Upvotes: 1