catch (SQLException ex) ^^^^^^ 有错! 我Java 也比较菜!"ConServer.java": Error #: 556 : exception java.sql.SQLException is never thrown in the corresponding try block at line 51, column 7
to GaoLun(★米老鼠★) 还是有错! catch (SQLException ex) ^^^^^^ 有错! 我Java 也比较菜!"ConServer.java": Error #: 556 : exception java.sql.SQLException is never thrown in the corresponding try block at line 51, column 7
直接改成 catch(Exception ex)
beyond_xiruo() 还是有错!
RS.next ^^^^ 这里错"ConServer.java": Error #: 360 : unreported exception: java.sql.SQLException; must be caught or declared to be thrown at line 53, column 15
public boolean has_child(int id) {
String cline="com.microsoft.jdbc.sqlserver.SQLServerDriver";//这里要有ms的JDBC,如果没有可以去microsoft的网站下载
String url="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=xiruo";
String user="sa";
String pass="";
Connection conn=null;
ResultSet rs=null;
String sql="select * from tree_folder where parentid="+id;
Class.forName(cline);
conn=DriverManager.getConnection(url,user,pass);
Statement stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
rs=stmt.executeQuery(sql);
if(rs.next())
return true;
else
return false;
}
我会感激不尽的!
你给我看看 可以嘛?
package teachtest;import java.awt.*;
import java.sql.*;public class ConServer {
String sDBDriver = "com.microsoft.jdbc.sqlserver.SQLServerDriver";
String sConnURL =
"jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=TeachTest";
String username = "sa";
String password = "9913089";
Connection conn = null;
ResultSet RS = null;
public ConServer() {
try {
Class.forName(sDBDriver);
}
catch (java.lang.ClassNotFoundException e) {
System.err.println("ConServer()" + e.getMessage());
}
} public ResultSet executeQuery(String SQL) {
RS = null;
try {
conn = DriverManager.getConnection(sConnURL, username, password);
Statement stmt = conn.createStatement();
RS = stmt.executeQuery(SQL);
}
catch (SQLException ex) {
System.err.println("ConServer.executeQuery:" + ex.getMessage());
}
return RS;
} public boolean has_child(int id) {
String strSQL = "select * from tree_folder where parentid=" + id;
ResultSet RS =null;
try {
conn = DriverManager.getConnection(sConnURL, username, password);
Statement stmt = conn.createStatement();
RS = stmt.executeQuery(strSQL);
}
catch (SQLException ex) {
System.err.println("ConServer.executeQuery:" + ex.getMessage());
}
if (RS.next())
return true;
else
return false;
}
}
"ConServer.java": Error #: 360 : unreported exception: java.sql.SQLException; must be caught or declared to be thrown at line 58, column 14
public boolean has_child(int id) {
String strSQL = "select * from tree_folder where parentid=" + id;
ResultSet RS =null;
try {
RS=executeQuery(strSQL);
}
catch (SQLException ex) {
System.err.println("ConServer.executeQuery:" + ex.getMessage());
return false;
}
if (RS.next())
return true;
else
return false;
}
}
^^^^^^
有错! 我Java 也比较菜!"ConServer.java": Error #: 556 : exception java.sql.SQLException is never thrown in the corresponding try block at line 51, column 7
你看看 错误消息
String strSQL = "select * from tree_folder where parentid=" + id;
ResultSet RS = null;
try {
RS = executeQuery(strSQL);
}
catch (SQLException ex) {
System.err.println("ConServer.executeQuery:" + ex.getMessage());
}while(RS.next)
{
rowscont++;
} if (rowscount!=0)
return true;
else
return false;
}
还是有错!
catch (SQLException ex)
^^^^^^
有错! 我Java 也比较菜!"ConServer.java": Error #: 556 : exception java.sql.SQLException is never thrown in the corresponding try block at line 51, column 7
catch(Exception ex)
还是有错!
^^^^
这里错"ConServer.java": Error #: 360 : unreported exception: java.sql.SQLException; must be caught or declared to be thrown at line 53, column 15
String strSQL = "select * from tree_folder where parentid=" + id;
try {
ResultSet RS=executeQuery(strSQL);
if(RS.next())
return true;
else
return false;
} catch (Exception ex) {
System.err.println("ConServer.executeQuery:" + ex.getMessage());
return false;
}
}
}
public boolean has_child(int id) throws Exception {
String strSQL = "select * from tree_folder where parentid=" + id;
ResultSet RS=executeQuery(strSQL);
if(RS.next())
return true;
else
return false;
}