java相关知识11.docVIP

  • 0
  • 0
  • 约3.48万字
  • 约 37页
  • 2016-11-27 发布于河南
  • 举报
java相关知识11

String?s?=?;??????????????????????????? ?BufferedReader?buf?=?new?BufferedReader(new?InputStreamReader( System.in));?????????????? ?s?=?buf.readLine(); 这就是在命令行中输入并读取一个字符串的代码 连接数据库 查看是否成功 查看客户端是否呼叫 { Connection con; PreparedStatement sql=null; try{Class.forName(com.mysql.jdbc.Driver);} catch (ClassNotFoundException e){System.out.println(fail); return; } try{con= DriverManager.getConnection(jdbc:mysql://:3306/data1, root, 123); if (!con.isClosed()) {System.out.println(Succeeded connecting to the Database!);} } catch (SQLException e){} ServerSocket server=null; Socket you=null; while(true) {try{server=new ServerSocket(3006); } catch (IOException e1) {System.out.println(listening);} try {System.out.println(waiting for call); you=server.accept(); System.out.println(peoples address:+you.getInetAddress()); } catch (IOException e){System.out.println(waiting for people);} } } 查询表数据 declare @sql nvarchar(100) declare @tableName nvarchar(100) declare cur cursor for select name from sysobjects where xtype=U --搜索所有表名 open cur while @@fetch_status=0 begin set @sql=select * from [ + @tableName + ] --循环查询表数据 exec sp_executesql @sql fetch next from cur into @tableName end close cur deallocate cur set nocount off String?str[]?=?dbname.split(,); ????????String?mark?=?str[0]; ????????tableName?=?str[1]; ????????int?i?=?Integer.parseInt(mark); 写在服务器端 java se5以后提供了一个比较好的输入方法 下面是一个小例子: import java.util.*; class test{ public static void main(String []args){ Scanner cin=new Scanner(System.in); System.out.println(请输入你的名字:); String name=cin.nextLine(); System.out.println(你输入你的年龄); int age=cin.nextInt(); System.out.println(你的名字是:+name+ +你的年龄是:+age);} } – 使用 nextToken每次取出一个分隔字符串 – 使用(countTokens)可以获悉分隔数量 或使用(hasMoreTokens)方法判断是否还有下一个 StringTokenizer tok = new StringTokenizer(input, delimiters); whil

文档评论(0)

1亿VIP精品文档

相关文档