Witam
Dopiero zaczynam się uczyć javy a wyapadło tak że muszę zrobić połączenie z bazą danych. Program działa do momentu wywołania zapytania Statment stm = polaczenie.createStatement(); i właśnie tutaj podświetla mi błąd przy zmiennej polaczenie nie rozumiem dlaczego w przykładach jakie widzialem w internecie.
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package baza;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
/**
*
* @author Jacek
*/
public class Baza {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
try{
String user="root";
String pass="";
String DB = "movies";
Class.forName("com.mysql.jdbc.Driver");//instalujemy sterownik jdbc
String connectionUrl = "jdbc:mysql://localhost/";// wskazujemy adres bazy
Connection polaczenie = DriverManager.getConnection(connectionUrl+DB,user,pass);
}catch (SQLException e){
System.out.println("SQL Exception: "+ e.toString());
}
catch(ClassNotFoundException cE){
System.out.println("Class not found exception : "+ cE.toString());
}
Statement stm = polaczenie.createStatment();
ResultSet rs = stm.executeQuery("Select * from categories");
}
}