안녕하세요, 제 코드에 무엇이 잘못되어 있는지 궁금 해서요. 제목에 오류가 있습니다. 이게 뭐가 잘못 되었 니? 미리 감사드립니다. 왜 나는 많은 세부 사항이 필요한데, 나는 충분히 설명했다.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");
}
}
}
'(로 변경
else() {
입니다. 그게 유효하다고 생각하니? –
오류의 원인인지 확실하지 않지만'else' 다음에'()'이 필요하지는 않습니다. – Joe
'else'다음에'()'을 제거한 후에도 문제가 계속 발생하면 알려주십시오. – starsplusplus