Bonjour je développe un logiciel de maillage de site avec java. je réussi à me connecter grace à ce driver( DbwConnection_0.9.5) à la base de donnée ciblée mais jai des erreurs.
voici la classe connexion
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
 
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
 
import javax.swing.JOptionPane;
 
import dbwConnection.DbwConnection;
 
 
public class Connexion {
	private String base,root,pwd;
 
	//private Statement stmt;
 
	private DbwConnection con;
 
	private String location;
 
	private String username;
 
	private String host;
 
	private String dataBase;
 
 
	public Connexion(String base,String root,String pwd){
		  // location = la ou se trove le fichier dbw.php sur votre serveur
         location = "http://site/dbw.php";
 
        // username = votre nom d'utilisateur pour vous connecter a votre base SQL
        username = "XXXXXXX";
 
        // pwd = votre mot de passe pour vous connecter a votre base SQL
         pwd = "XXXXXXX";
 
        // host = l'adresse de votre serveur SQL /
         host = "XXXXXXXXX";
 
        // dataBase = le nom de votre base de donnee SQL.
         dataBase = "XXXXXXXX";
 
        // impératif de mettre des try/catch, pour capturer les exceptions
 
	}
 
	public Boolean connecte(){
		  boolean connection = false;
		  // location = la ou se trove le fichier dbw.php sur votre serveur
	         location = "http://site/dbw.php";
 
	        // username = votre nom d'utilisateur pour vous connecter a votre base SQL
	        username = "XXXXXXXXXXXX";
 
	        // pwd = votre mot de passe pour vous connecter a votre base SQL
	         pwd = "XXXXXXXXXXXXX";
 
	        // host = l'adresse de votre serveur SQL /
	         host = "XXXXXXXXXXXX";
 
	        // dataBase = le nom de votre base de donnee SQL.
	         dataBase = "db352963047";
 
	        // impératif de mettre des try/catch, pour capturer les exceptions
 
 
		  try {
 
			  //	DriverManager.registerDriver (new com.mysql.jdbc.Driver());
			  	  con = new DbwConnection(location, username, pwd, host, dataBase);
 
			  	/*con =  DriverManager.getConnection ("jdbc:mysql://XXXXXXX:3306/"+"XXXXXXXX", "XXXXxx","XXXXXXXX");// user, passwd
			  */
			  //	con = DriverManager.getConnection( "jdbc:mysql://dXXXX/XXXXXX;user=SSSSSpassword=XXXXXx");
			  	connection = true;
 
				System.out.println("Connexion établie");
				//stmt  = ((Connection) con).createStatement();
		  } catch (SQLException e) {
			  System.out.println(e);
				JOptionPane.showMessageDialog(null, "Une erreur vient de surgir!\nLa connexion n'a pas réussi à s'effectuer normalement !!!!");			//e.printStackTrace();
 
			}
		return connection;
 
	}
 
 
	/*public Statement getStatement(){
		return stmt;
	}*/
 
 
	public DbwConnection getConnexion(){
		return   con;
	}
 
	public String getBase(){
		return base;
	}
 
/*	public void close(){
 
		 if(stmt!=null)
	            try {
	            	con.commit();
	     		stmt.close();
	     	} catch (SQLException e) {
	     		e.printStackTrace();
	     	}
	}
*/
 
 
}
Il ya pas de probleme de connexion
Voila la classe qui génére l'erreur
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
package Maillage;
 
import java.sql.Connection;
import java.sql.DatabaseMetaData;
 
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
 
import Connexion.Connexion;
 
 
 
import java.util.ArrayList;
 
import java.util.Vector;
 
import javax.swing.JTextField;
 
 
 
 
 
public class lister_tables2 {
 
 
	private ResultSet rs;
 
	Vector<Object> v=new Vector<Object>();
 
 
	private String base=null;
	Connection con;
 
	private Recuperer_Liens_Ancres donnees; 
 
 
	private ArrayList<JTextField> motcleUrl;
 
 
	public lister_tables2(Connexion con,Recuperer_Liens_Ancres donnees, ArrayList<JTextField> motsCle_Et_Url ) {
 
		this.donnees=donnees;
		this.con=  (Connection) con.getConnexion();
		this.motcleUrl=motsCle_Et_Url;
 
		//		System.out.println(con.getBase());
 
 
 
		Vector s=new Vector();
 
		this.base=con.getBase();
 
		DatabaseMetaData md;
		try {
			md = this.con.getMetaData();
			rs = md.getTables(null,null, "%", null);
		int i=0;
 
 
		while (rs.next()) {
			// System.out.println(rs.getString(3));
			s.add(rs.getString(3));
			//System.out.println(++i);
		}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
 
 
		//System.out.println(s.get(3));
		for(int t=0;t<s.size();t++){
			getdata(s.get(t).toString());
		}
 
	}
 
	public void getdata(String table){
		try {
			int i=0;
			Statement st = (Statement) con.createStatement();
			//System.out.println("table   "+table);
			rs=st.executeQuery("select * from "+table);
			//System.out.println()
			i=rs.getMetaData().getColumnCount();
			//for(int a=1;a<i;a++){
			int j=i;
			while(rs.next()){		
				while(j>0){
					//System.out.println(rs.getString(j));
					recherche(rs.getString(j),
							table,
							j,
							rs.getMetaData().getColumnName(j));
 
					j=j-1;
				}j=i;
 
			}
 
 
 
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			//e.printStackTrace(); Il y' a une exception sur le timestame 
		}
 
	}
 
	/*
	 * 
	 * 
	 * 
	 */
	public void recherche(String  chaine,String tablename,int a,String nomColon) throws SQLException{
		//System.out.println("la recherche   "+chaine);
		for (int e =0;e< donnees.getData().size();e++ ){
			//System.out.println(" traore "+donnees.getData().elementAt(0));&rsquo;intégralité de votre contenu dans WordPress.
		if(chaine.contains(donnees.getData().elementAt(e).toString())){
			System.out.println("Nom table "+tablename+" Numero colonne "+a+"  texte   "+chaine+"   Equivalance   "+donnees.getData().elementAt(e).toString());
			replaceMot( chaine,tablename,nomColon);
		}
		}
	}
 
	public void Update(String  chaineUpdate,String chaineReplace,String NomTable,String base,String nomColon) throws SQLException{
		String requetUpdate="UPDATE `"+base+"`.`"+NomTable+"` SET `"+nomColon+"` = '"+chaineReplace+"' WHERE `"+NomTable+"`.`"+nomColon+"` = '"+chaineUpdate+"'";
		gestion_Update(requetUpdate);
 
 
	}
 
 
	public void gestion_Update(String reket){
		try {
			Statement st = (Statement)  con.createStatement();
			st.executeUpdate(reket);
			con.setAutoCommit(true);
 
 
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
 
	}
 
	public void replaceMot(String chaine,String tablename,String nomColon){
 
		for(int i=0;i<motcleUrl.size()-1;i++){
			if(chaine.contains(motcleUrl.get(1).getText()+"</a>")||chaine.contains(motcleUrl.get(1).getText()+" </a>")){
 
			}else{
				if(chaine.contains(motcleUrl.get(1).getText())){System.out.println("tttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttt");
					String chaineReplace = chaine.replaceAll(motcleUrl.get(1).getText(), "<a href=\""+motcleUrl.get(i).getText()+"\">"+motcleUrl.get(1).getText()+"</a>");
					 try {
						Update(chaine,chaineReplace, tablename,this.base,nomColon);
					} catch (SQLException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
				}
			}
		}
	}
 
	/*public void test(int i) throws SQLException{
	  for(int a=1;a<=i;a++){
		  v.add(rs.getString(a));
	  }
  }
 
	 */}
cette classe génére l'erreur suivante
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
 
java.lang.ClassCastException: dbwConnection.DbwConnection cannot be cast to java.sql.Connection
	at Maillage.lister_tables2.<init>(lister_tables2.java:44)
	at Vues.ComposanteMenu.actionPerformed(Composants1.java:375)
je pense que le from vient de l'utilisation de
-getMetaData()
-ResultSet
Aider moi svp sa fait des jours que je cherche une solution
merci pour vos reponse