Diego_Armando
30-05-2004, 15:59
Ciao!
Ho scritto un programmino in Java per effettuare delle query su un database.
Compilandolo mi da:
C:\jena>javac jdbcpr.java
jdbcpr.java:12: illegal start of expression
throws IOException
^
jdbcpr.java:47: ';' expected
}catch ( Exception e ) { e.printStackTrace();}
^
2 errors
import java.sql.*;
import java.io.*;
class jdbcpr {
public static void main(String[] args)
{
String[] ricerca = new String[100];
throws IOException
{
BufferedReader br = new BufferedReader ( new InputStreamReader (System.in));
String str[] = new String[100];
System.out.println("Inserire stringa");
for(int i=0;i<100;i++) {
str[i] = br.readLine();
if ( str[i].equals ("stop")) break;
}
for ( int i=0;i<100;i++ ) {
if (str[i].equals("stop")) break;
ricerca[i] = str[i];
}
}
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String URL = "jdbc:odbc:db1";
Connection con;
con = DriverManager.getConnection(URL);
Statement query = con.createStatement();
ResultSet result = query.executeQuery("Select '" + ricerca + "' from dbprova");
while (result.next ()) {
String nome =
result.getString("nome");
System.out.println(nome);
}
}catch ( Exception e ) { e.printStackTrace();}
}
}
Un'ultima cosa...come faccio a prendere una stringa in input da console e passarla alla query?
Grazie mille..
Ho scritto un programmino in Java per effettuare delle query su un database.
Compilandolo mi da:
C:\jena>javac jdbcpr.java
jdbcpr.java:12: illegal start of expression
throws IOException
^
jdbcpr.java:47: ';' expected
}catch ( Exception e ) { e.printStackTrace();}
^
2 errors
import java.sql.*;
import java.io.*;
class jdbcpr {
public static void main(String[] args)
{
String[] ricerca = new String[100];
throws IOException
{
BufferedReader br = new BufferedReader ( new InputStreamReader (System.in));
String str[] = new String[100];
System.out.println("Inserire stringa");
for(int i=0;i<100;i++) {
str[i] = br.readLine();
if ( str[i].equals ("stop")) break;
}
for ( int i=0;i<100;i++ ) {
if (str[i].equals("stop")) break;
ricerca[i] = str[i];
}
}
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String URL = "jdbc:odbc:db1";
Connection con;
con = DriverManager.getConnection(URL);
Statement query = con.createStatement();
ResultSet result = query.executeQuery("Select '" + ricerca + "' from dbprova");
while (result.next ()) {
String nome =
result.getString("nome");
System.out.println(nome);
}
}catch ( Exception e ) { e.printStackTrace();}
}
}
Un'ultima cosa...come faccio a prendere una stringa in input da console e passarla alla query?
Grazie mille..