看看这个程序,到底是为什么??在同一个类中不能调用方法

luoxingke 2003-10-17 07:54:29
import java.io.*;
import java.net.*;
import java.sql.*;

public class simplesqlserver
{
boolean check(String num) {
int i,j;
String strTemp;
strTemp="0123456789+'_'";
if (num.length()== 0)
return false;
for (i=1;i<num.length();i++)
{
j=strTemp.indexOf(num.charAt(i));
if (j==-1)
{
return false;
}
}
return true;
}
public static void main(String args[])
{
Socket clientSocket;
ServerSocket serverSocket;
PrintStream ps;
BufferedReader br;
String inString="";
Connection con;
Statement bb;
ResultSet rs;
BufferedWriter bw;
try{
serverSocket=new ServerSocket(8888);
clientSocket=serverSocket.accept();
br=new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));
bw=new BufferedWriter(new OutputStreamWriter(clinetSocket.getOutputStream()));
inString=br.readLine();
if(check(inString))
{ ps.println(inString); }
else
{ System.out.println("此表名无效,请重新输入!"); }
Class.forName("oracle.jdbc.driver.OracleDriver");
con=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:oracle","scott","tiger");
bb=con.createStatement();
bb.executeUpdate("drop table "+inString+"");
System.out.println("Table"+inString+" droped");
("create table "+inString+"(empid integer,name varchar(20),dept number(4))");
System.out.println("Table"+inString+" created");
bb.executeUpdate("insert into "+inString+" values(1,'myboy',1423)");
System.out.println("Number of rows inserted=1");
bb.executeUpdate("delete "+inString+" where empid=1");
System.out.println("Number of rows deleted=1");
bb.close();
con.close();
br.close(); }
catch(IOException es) {}
catch(ClassNotFoundException ed) {}
catch(SQLException e)
{
System.out.println(e.getErrorCode());
if(e.getErrorCode()==903 ||e.getErrorCode()==911 ||e.getErrorCode()==922 ||e.getErrorCode()==942 )
{
try{
Class.forName("oracle.jdbc.driver.OracleDriver");
con=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:oracle","scott","tiger");
bb=con.createStatement();
System.out.println("Table"+inString.toString()+" has been a table!");
System.out.println("create table "+inString.toString()+"(empid integer,name varchar(20),dept number(4))");
bb.executeUpdate("create table "+inString+" (empid integer,name varchar(20),dept number(4))");
System.out.println("Table"+inString.toString()+" created");
bb.executeUpdate("insert into "+inString.toString()+" values(1,'myboy',1423)");
System.out.println("Number of rows inserted=1");
bb.executeUpdate("delete "+inString.toString()+" where empid=1");
System.out.println("Number of rows deleted=1"); }
catch(SQLException ex){ System.out.println(ex); }
catch(Exception ea) { System.out.println(ea); }
}
}
}
}
调用if(check(inString))时出错,说找不到check,请指点!!
...全文
35 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
imagex 2003-10-17
  • 打赏
  • 举报
回复
static boolean check()
LuZhou 2003-10-17
  • 打赏
  • 举报
回复
static boolean check()
wellsoon 2003-10-17
  • 打赏
  • 举报
回复
要么如楼上所说,要么:

public static void main(String args[])
{
simplesqlserver newclass= new simplesqlserver();
newclass.check();

.......

}
LoveRose 2003-10-17
  • 打赏
  • 举报
回复
用static声明的函数只能调用static声明的函数和变量
你的程序中public static void main() 不能调用boolean check()

必须把check()声明为 static boolean check()

62,614

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧