Liste déroulante avec mysql et jsp
Bonjour tout le monde ,
Voila j'ai un probléme avec mon scripte car je veux lister un champ d'une table de ma base mysql sur mon formulaire mais il me renvoie une erreur voici mon code:
Code:
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
| <%
public static void main(String[] args)
{
//try block for sql exceptions
try
{
//create driver - ALTER TO SUIT YOUR DRIVER/ DBMS
Class.forName("com.mysql.jdbc.Driver").newInstance();
//database connection code - ENTER YOUR DETAILS
String username = "root";
String password = "admin";
//URL - ALTER TO CONNECT TO YOUR DATABASE
String dbURL = "jdbc:mysql://localhost/sms?user="
+ username + "&password=" + password;
//create the connection - ALTER FOR YOUR DBMS
java.sql.Connection myConnection =
DriverManager.getConnection(dbURL);
//create statement handle for executing queries
Statement stat = myConnection.createStatement();
}
catch( Exception E )
{ System.out.println( E.getMessage() ); }
}
String selectQuery = "Select nom_canal from short_numbers";
//get the results
ResultSet results = stat.executeQuery(selectQuery);
//output the results
while (results.next())
{
String nom_canal=results.getString("nom_canal");
//example - column is called 'firstname'
out.println("<option>" +
results.getString("nom_canal")+"</option>");
}
%> |
et voici l'erreur qu'il envoie:
Code:
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
| description Le serveur a rencontr� une erreur interne () qui l'a emp�ch� de satisfaire la requ�te.
exception
org.apache.jasper.JasperException: Impossible de compiler la classe pour la JSP:
Une erreur s'est produite � la ligne: 249 dans le fichier jsp: /stat-pseudo.jsp
void is an invalid type for the variable main
246: <select name="nom_canal">
247: <option value="0">-Choisir salon-</option>
248: <%
249: public static void main(String[] args)
250: {
251: //try block for sql exceptions
252: try
Une erreur s'est produite � la ligne: 249 dans le fichier jsp: /stat-pseudo.jsp
Syntax error on token "(", ; expected
246: <select name="nom_canal">
247: <option value="0">-Choisir salon-</option>
248: <%
249: public static void main(String[] args)
250: {
251: //try block for sql exceptions
252: try
Une erreur s'est produite � la ligne: 249 dans le fichier jsp: /stat-pseudo.jsp
Syntax error on token ")", ; expected
246: <select name="nom_canal">
247: <option value="0">-Choisir salon-</option>
248: <%
249: public static void main(String[] args)
250: {
251: //try block for sql exceptions
252: try
Une erreur s'est produite � la ligne: 278 dans le fichier jsp: /stat-pseudo.jsp
stat cannot be resolved
275: }
276: String selectQuery = "Select nom_canal from short_numbers";
277: //get the results
278: ResultSet results = stat.executeQuery(selectQuery);
279: //output the results
280: while (results.next())
281: {
Stacktrace:
org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:92)
org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:330)
org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:423)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:317)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:295)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:282)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:586)
org.apache.jasper.servlet.JspServletWrapper.service |
Merci de bien vouloir m'aider