這是一個Java代碼,我在Eclipse中編寫從MySQL數據庫檢索信息..但編譯器給出錯誤,說conn不能解析爲類型..任何人都可以請告訴我,我可能會做什麼?Eclipse編譯器錯誤說連接變量不能解析到一個類型
import java.sql.*;
public class plh {
static Connection conn=null;
static Statement s=null;
public static void main(String[] args){
try {
Class.forName("com.mysql.jdbc.Driver");
conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/wonkashop","root", "");
String st= new String("select * from users;");
s= new conn.createStatement(st);//ERROR.. why??
}
catch (Exception e) {
System.out.println("Unable to connect to Database");
}
}
}
FYI createStatement()不接受任何參數 – Prabhaker
噢,謝謝。修復。 –