Code java pour remplir le carnet d`adresse

publicité
import java.io.*;
import java.util.*;
import java.sql.*;
Code java pour remplir le carnet
d’adresse
public class jdbc1 {
public static void main(String[] args)throws java.io.IOException{
BufferedReader in = new BufferedReader( new InputStreamReader(System.in));
System.out.println("JDBC");
Connection connection = null;
try {
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
DriverManager.registerDriver(new com.microsoft.jdbc.sqlserver.SQLServerDriver());
}
catch (Exception E) {
System.out.println("Unable to load driver.");
System.out.println(E.getMessage());
E.printStackTrace();
return;
}
try {
connection = DriverManager.getConnection(
"jdbc:microsoft:sqlserver://localhost:1433;user=sa;password=;DatabaseName=Carnet_dadresses");
}
catch (Exception E) {
System.out.println("Unable to connect.");
System.out.println(E.getMessage());
E.printStackTrace();
return;
}
try {
Statement Stmt = connection.createStatement();
int Resultat = Stmt.executeUpdate( "INSERT INTO carnet VALUES ( 'Amis', 'Pouchkine',' Alexandre', '12.Rue de
Stalingrad', '520760', 'Moscou', 'Russie', '950.56.58.12', NULL, NULL);");
System.out.println("Nombre d'enregistrements modifi?s : " + Resultat);
}
catch (Exception E) {
System.out.println("Unable to query.");
System.out.println(E.getMessage());
E.printStackTrace();
Code SQL pour crée la DataBase
return;
Carnet_dadresses
et la table carnet
}
System.out.println("Done !");
}
}
create database Carnet_dadresses
create table carnet
(Categorie Varchar (20) not null,
Nom varchar (20) not null,
Prenom Varchar (20)
not null,
Adresse Varchar (50),
CodePostal Varchar (10),
Ville Varchar (30),
Pays Varchar (30),
Telephone Varchar (20),
Mobile Varchar (20),
DateDeNaissance Varchar (20),
constraint pk_nomprenom
primary key (Nom,Prenom));
Téléchargement
Explore flashcards