2014-01-14 5 views
-3

안녕하세요, 제 코드에 무엇이 잘못되어 있는지 궁금 해서요. 제목에 오류가 있습니다. 이게 뭐가 잘못 되었 니? 미리 감사드립니다. 왜 나는 많은 세부 사항이 필요한데, 나는 충분히 설명했다.JAVA 오류; 예기치 않은 문장이없는 경우 예기치 않은 경우

public class Connect { 
public Connect() throws SQLException{ 
    makeConnection(); 
} 

private Connection koneksi=null; 
PreparedStatement pst = null; 
ResultSet rs = null; 
public static String [] data=new String[50]; 
public Connection makeConnection() throws SQLException { 
    if (koneksi == null) { 
     new Driver(); 
     // buat koneksi 
     koneksi = DriverManager.getConnection(
        "jdbc:mysql://localhost:3306/songlist", 
        "root", 
        ""); 

     pst = koneksi.prepareStatement("SELECT * FROM lagusedih "); 
     rs = pst.executeQuery(); 
     int i=0; 
     while (rs.next()) { 
      System.out.print(rs.getString(1));data[i]=rs.getString(1); 
      System.out.print(":"); 
      System.out.print(rs.getString(2)); 
      System.out.print(":"); 
      System.out.println(rs.getString(3)); 
      i++; 
     } 

    return koneksi; 
    } 
     else() { 
     Driver driver = new Driver(); 
      koneksi = DriverManager.getConnection(
        "jdbc:mysql://localhost:3306/songlist", 
        "root", 
        ""); 
     pst = koneksi.prepareStatement("SELECT * FROM lagugembira "); 
     rs = pst.executeQuery(); 
     int i=0; 
     while (rs.next()) { 
      System.out.print(rs.getString(1));data[i]=rs.getString(1); 
      System.out.print(":"); 
      i++; 
     } 
} 
return koneksi; 

}

public static void main(String args[]) { 
    try { 
     Connect c = new Connect(); 
     System.out.println("Connection established"); 
    } 
    catch (SQLException e) { 
     e.printStackTrace(); 
     System.err.println("Connection Failure"); 
    } 

} 

}

+5

'(로 변경

else() { 

else() {

입니다. 그게 유효하다고 생각하니? –

+0

오류의 원인인지 확실하지 않지만'else' 다음에'()'이 필요하지는 않습니다. – Joe

+0

'else'다음에'()'을 제거한 후에도 문제가 계속 발생하면 알려주십시오. – starsplusplus

답변

2

이 줄 else() {은 고장 - 괄호를 제거합니다.

2

오류는`) 다른

else { 
+0

감사합니다. 내 문제가 해결되었습니다. – buzzer