Bom dia,
eu preciso criar o banco de dados e as tabelas do banco quando abro o programa pela primeira vez. Ele instala, roda mas não cria as tabelas e nem o banco. Alguém poderia me dizer o que está errado com o código ou como que faço da forma correta? Obrigado.
String sqlcreate = "CREATE DATABASE DBAllure";
String sqluse = "USE DBAllure";
String sqlagenda = "CREATE TABLE agenda ( idagenda integer NOT NULL, idcliente integer NOT NULL, " +
"agenome character varying(15) NOT NULL, agesobrenome character varying(30) NOT NULL, " +
"agedata date NOT NULL, agehora time without time zone NOT NULL, CONSTRAINT idagenda_pk PRIMARY KEY (idagenda ))";
String sqlclientes = "CREATE TABLE clientes ( idcliente integer NOT NULL, clinome character varying(15) NOT NULL, " +
"clisobrenome character varying(30) NOT NULL, clidatanasc date NOT NULL, clirg character varying(20) NOT NULL, " +
"cliuf character varying(2) NOT NULL, clicep character varying(10), clicidade character varying(40), " +
"clibairro character varying(40), clirua character varying(40), clinumero integer, " +
"clicomplemento character varying(40), clitelres character varying(14), clitelcel character varying(14), " +
"clitelcom character varying(14), cliplanodesaude character varying(40) NOT NULL, cliemail character varying(40), " +
"cliobservacao character varying(400), CONSTRAINT clientes_pkey PRIMARY KEY (idcliente ))";
String sqlconsultas = "CREATE TABLE consultas ( idconsulta integer NOT NULL, idcliente integer NOT NULL," +
"condata date NOT NULL, conhora time without time zone NOT NULL, conobservacao character varying(400), " +
"CONSTRAINT consultas_pkey PRIMARY KEY (idconsulta ))";
String sqllogin = "CREATE TABLE login ( idlogin integer NOT NULL, logaccount character varying(20) NOT NULL, " +
"logpassword character varying(20) NOT NULL, acesso integer, CONSTRAINT login_pkey PRIMARY KEY (idlogin ))";
String sqlplanos = "CREATE TABLE planos ( idplano integer NOT NULL, nomeplano character varying(30) NOT NULL, " +
"CONSTRAINT pk_planos PRIMARY KEY (idplano ))";
String sqlresponsavel = "CREATE TABLE responsavel ( idresponsavel integer NOT NULL, idcliente integer NOT NULL, " +
"respnome character varying(40) NOT NULL, respsobrenome character varying(40) NOT NULL, respdatanasc date NOT NULL, " +
"resprg character varying(20) NOT NULL, respuf character varying(2) NOT NULL, respcep character varying(10), " +
"respcidade character varying(40), respbairro character varying(40), resprua character varying(40), " +
"respnumero integer, respcomplemento character varying(40), resptelres character varying(14), " +
"resptelcel character varying(14), resptelcom character varying(14), respemail character varying(40), " +
"respobservacao character varying(400), CONSTRAINT responsavel_pkey PRIMARY KEY (idresponsavel ))";
try {
JOptionPane.showMessageDialog(null, "Chegou até aqui");
s.execute(sqlcreate);
s.execute(sqluse);
s.execute(sqlagenda);
s.execute(sqlclientes);
s.execute(sqlconsultas);
s.execute(sqllogin);
s.execute(sqlplanos);
s.execute(sqlresponsavel);
JOptionPane.showMessageDialog(null, "Chegou até aqui também");
} catch (SQLException e) {
e.printStackTrace();
}