Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
- */
- package pkgPrincipal;
- /**
- *
- * @author root
- */
- import org.jdesktop.swingx.plaf.nimbus.NimbusLookAndFeel;
- import javax.swing.UIManager;
- import javax.swing.JOptionPane;
- import java.sql.Connection;
- import java.sql.Statement;
- import java.sql.ResultSet;
- import java.sql.DriverManager;
- import java.sql.SQLException;
- import com.mysql.jdbc.Driver;
- import com.mysql.jdbc.exceptions.jdbc4.CommunicationsException;
- public class Principal {
- //private
- private Connection conn = null;
- private Statement stmnt = null;
- //public
- public String host = null;
- public ResultSet rs = null;
- public void Principal() throws SQLException{
- host = JOptionPane.showInputDialog(null,"Qual sera o endereco do Banco de Dados?","Projeto11102008",JOptionPane.INFORMATION_MESSAGE);
- if(host.toString().equals("") | host.toString().equals(" ") | host.toString().equals(null)){
- }
- ConectaBanco();
- }
- private void ConectaBanco() throws SQLException{
- try{
- Driver drv = new Driver();
- conn = DriverManager.getConnection("jdbc:mysql://"+host.toString()+":3306/sistema","root","root@mysql@pedrohms");
- if(conn.isValid(5000)){
- stmnt = conn.createStatement();
- rs = stmnt.executeQuery("Select * from log_principal");
- }
- }catch(SQLException e){
- if(e.getMessage().toString().equals("Table \'sistema.log_principal\' doesn\'t exist")){
- JOptionPane.showMessageDialog(null,"Tabela nao existe","erro",JOptionPane.ERROR_MESSAGE);
- if(JOptionPane.showConfirmDialog(null, "Voce gostaria que o sistema crie a tabela?","Projeto11102008",JOptionPane.YES_NO_OPTION,JOptionPane.QUESTION_MESSAGE)==JOptionPane.YES_OPTION){
- stmnt.execute("create table log_principal(id_log BIGINT(18) NOT NULL AUTO_INCREMENT,log VARCHAR(100),user VARCHAR(255),PRIMARY KEY(id_log))");
- }
- }else if(e.getClass() == CommunicationsException.class){
- JOptionPane.showMessageDialog(null,"Host nao encontrado !","Projeto11102008",JOptionPane.ERROR_MESSAGE);
- }
- }
- }
- public static void main(String args[]){
- try{
- UIManager.setLookAndFeel(new NimbusLookAndFeel());
- Principal principal = new Principal();
- principal.Principal();
- }catch(Exception e){
- JOptionPane.showMessageDialog(null,e.getMessage(),"erro",JOptionPane.ERROR_MESSAGE);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement