Skip to content
Browse files

Install DB Completed

  • Loading branch information...
1 parent a370512 commit 132d331384595d7a9bf429854e28d2f1732a3c76 @thomasabraham committed Oct 14, 2011
Showing with 64 additions and 10 deletions.
  1. +54 −10 src/installdb.java
  2. +10 −0 src/query.java
View
64 src/installdb.java
@@ -1,4 +1,6 @@
import javax.swing.JFrame;
+import java.io.FileWriter;
+import java.io.IOException;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.event.ActionListener;
@@ -9,6 +11,7 @@
import javax.swing.JButton;
import javax.swing.JRadioButton;
import javax.swing.JTextField;
+import javax.swing.JPasswordField;
import javax.swing.JCheckBox;
class InstallDB implements ActionListener{
JFrame win;
@@ -18,7 +21,8 @@
int ns,cs;
JRadioButton mysql,oracle;
ButtonGroup dbms;
- JTextField url,uname,pwd;
+ JTextField url,uname;
+ JPasswordField pwd;
JCheckBox savepwd;
public InstallDB(){
win = new JFrame();
@@ -71,14 +75,14 @@ public void windowClosing(WindowEvent we){
chooseDbms.add(mysql);
chooseDbms.add(oracle);
url = new JTextField(40);
- url.setText("localhost");
+ url.setText("jdbc:mysql://localhost:3306/");
urlPanel = new JPanel();
urlPanel.add(new JLabel("URL : "));
urlPanel.add(url);
authPanel = new JPanel();
authPanel.setLayout(new GridLayout(0,4));
uname = new JTextField(20);
- pwd = new JTextField(20);
+ pwd = new JPasswordField(20);
authPanel.add(new JLabel(" "));
authPanel.add(new JLabel("UserName : ",JLabel.RIGHT));
authPanel.add(uname);
@@ -106,18 +110,13 @@ public void actionPerformed(java.awt.event.ActionEvent ae){
}else if(ae.getSource()==finish){
System.exit(0);
}else if(ae.getSource()==next){
- finish();
+ cs++;
start();
}else if(ae.getSource()==previous){
cs--;
start();
}
}
- public void finish(){
- if(cs == 1||cs == 2||cs == 3){
- cs++;
- }
- }
public void start(){
if(cs == 1)
startStep1();
@@ -127,6 +126,8 @@ else if(cs == 3)
startStep3();
else if(cs == 4)
startStep4();
+ else if(cs == 5)
+ startStep5();
}
public void startStep1(){
previous.setEnabled(false);
@@ -156,11 +157,54 @@ public void startStep3(){
}
public void startStep4(){
step.setText("Step "+cs+"/"+ns);
+ next.setEnabled(true);
message.setText("<html>Enter your username and password.<br/><br/>Contact DBMS Administrator if you don't have. </html>");
centerPanel.setVisible(false);
centerPanel.remove(urlPanel);
centerPanel.add(APC);
centerPanel.setVisible(true);
}
- //To Do ; add functions for each step.
+ public void startStep5(){
+ step.setText("Step "+cs+"/"+ns);
+ message.setText("<html>Please wait while we test your DBMS connection.<br/><br/>Make sure that you are connected to DBMS server. </html>");
+ next.setEnabled(false);
+ centerPanel.setVisible(false);
+ centerPanel.remove(APC);
+ centerPanel.setVisible(true);
+ String driver,urlstr="URL=";
+ if(oracle.isSelected())
+ driver = "DRIVER=sun.jdbc.odbc.JdbcOdbcDriver";
+ else if(mysql.isSelected())
+ driver = "DRIVER=com.mysql.jdbc.Driver";
+ else
+ driver = "Replace with driver";
+ driver+="\n";
+ urlstr += url.getText();
+ urlstr+="\n";
+ String unamestr = "USERNAME=";
+ unamestr += uname.getText();
+ unamestr+="\n";
+ String pass = "PASSWORD=";
+ pass += pwd.getPassword().toString();
+ pass+="\n";
+ try{
+ FileWriter confile = new FileWriter(".apms.conf");
+ confile.write(driver.toCharArray(),0,driver.length());
+ confile.write(urlstr.toCharArray(),0,urlstr.length());
+ confile.write(unamestr.toCharArray(),0,unamestr.length());
+ if(savepwd.isSelected()){
+ confile.write(pass.toCharArray(),0,pass.length());
+ }
+ confile.close();
+ }catch(IOException e){
+ //to do print dialog box specifing error;
+ }
+ Query q = new Query();
+ if(q.testDbmsConnection()){
+ message.setText("<html>Installation Completed Sucessfully.<br/>Press finish button to exit.</html>");
+ }else{
+ message.setText("<html>Installation Failed.<br/>Press finish button to exit or go back and change something.</html>");
+ }
+ finish.setEnabled(true);
+ }
}
View
10 src/query.java
@@ -82,4 +82,14 @@ void addcat(String name, String cat){
System.out.println(e.getMessage());
}
}
+ public boolean testDbmsConnection(String Pass){
+ int i=0;
+ i++;
+ return true;
+ }
+ public boolean testDbmsConnection(){
+ int i=0;
+ i++;
+ return true;
+ }
}

0 comments on commit 132d331

Please sign in to comment.
Something went wrong with that request. Please try again.