JAVA错误;如果没有,预计不会发表声明

时间:2014-01-14 15:09:23

标签: java if-statement netbeans-7

嗨我想知道我的代码有什么问题我得到了标题中说明的错误。这有什么问题?提前致谢。为什么我需要这么多细节,我觉得我已经很好地描述了它。

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");
     }  

}

}

2 个答案:

答案 0 :(得分:2)

此行else () {已损坏 - 请删除括号。

答案 1 :(得分:2)

错误为else () {

更改

else () {

else  {