关于java链接mysql出错

import java.sql.*;
import java.sql.SQLException;

public class DengLu {
Connection con;
Statement sql;
ResultSet rs;
try{
Class.forName("com.mysql.jdbc.Driver");
}
catch(SQLException e){}
try{
con = DriverManager.getConnection("jdbc:mysql://localhost:3306/factory", "root", "d94h04x12");
sql = con.createStatement();
rs = sql.executeQuery("SELECT * FROM employee");
}
catch(SQLException e1){}
}
提示syntax error on token";", { expected after this token

你的class内为什么写try代码了,那些要写到方法里面,不能和变量声明写到一层上

把你的代码放到main方法中,么有主方法啊!

public class DengLu {

public static void main(String[] args){

//写在这里
try{.....}

}

}

类中应该有个方法。。。。

请申明一个方法,然后将

 try{
Class.forName("com.mysql.jdbc.Driver");
}
catch(SQLException e){}
try{
con = DriverManager.getConnection("jdbc:mysql://localhost:3306/factory", "root", "d94h04x12");
sql = con.createStatement();
rs = sql.executeQuery("SELECT * FROM employee");
}
catch(SQLException e1){}
}
```放入该方法内即可解决阁下的问题

神奇的代码,⊙ω⊙楼主是怎么写出来的?

明显是个新手,你们不要笑。。

先好好看书再问问题,,,