老兄,""表示string结束,你要用\"转换

解决方案 »

  1.   

    成功的原因是因为你把本来调用一个参数的getConnection方法变成了调用3个参数的了
      

  2.   

    public static Connection getConnection(String url,
                                           String user,
                                           String password)
                                    throws SQLException
    Attempts to establish a connection to the given database URL. The DriverManager attempts to select an appropriate driver from the set of registered JDBC drivers.Parameters:url - a database url of the form jdbc:subprotocol:subname
    user - the database user on whose behalf the connection is being made
    password - the user's passwordReturns:a connection to the URLThrows:SQLException - if a database access error occursconnectstring="jdbc:microsoft:sqlserver://192.168.0.21:1433","study","study";
    only a String ,so it is wrong for that!        
      

  3.   

    String url = "jdbc:microsoft:sqlserver://192.168.0.21:1433";
    String user = "study";
    String password = "study";
    conn = DriverManager.getConnection(url, user, password);
      

  4.   


    conn=DriverManager.getConnection("jdbc:microsoft:sqlserver://192.168.0.21:1433","study","study"
    );--------------------------->String a="jdbc:microsoft:sqlserver://192.168.0.21:1433";
    Strign b="study";
    String c="study";
    conn=DriverManager.getConnection(a,b,c);
      

  5.   

     
     Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
       con = DriverManager.getConnection
         ("jdbc:microsoft:sqlserver://192.168.5.219:1433;DatabaseName=数据库名","用户名","密码");
      

  6.   

    你应该去看一下MS SQLSERVER2000 JDBC 的帮助文件,里面有详细的例子
      

  7.   

    兄弟们我的问题是这样的,我的连接信息是从文件里面读出来的,那个文件就像ini文件
    其中有一项是连接串,但是我搞来搞去这个字符串不知道该写什么。
    我写成
    "jdbc:microsoft:sqlserver://192.168.0.21:1433","study","study"
    连接数据库不行,写成
    "jdbc:microsoft:sqlserver://192.168.0.21:1433,study,study"
    也不行!
    大家说到底如何处理
      

  8.   

    写成
    "jdbc:microsoft:sqlserver://192.168.0.21:1433,study,study"
    然后用StringTokenizer 或者其它的把它分成三个String变量如
    S1="jdbc:microsoft:sqlserver://192.168.0.21:1433";
    s2="study";
    s3="study";
      

  9.   

    或者把那个文件就像ini文件,里面有一项是连接串,变成三项,不也一样嘛!!!
      

  10.   

    1.jdbc下载:http://www.microsoft.com/china/sql/downloads/2000/jdbc.asp
    后setup.
    2.加入classpath中
    ______________________________________________________________________
    <%@ page contentType = "text/html; charSet=gb2312" %>
    <%@ page language="java" import = "java.sql.*" %>
    <%
      /**address: SQL Server的连接参数*/
      String address = "jdbc:microsoft:sqlserver://127.0.0.1:1433";
      /***user: 数据库用户名*/
      String user="sa";
      /**passwd: 用户密码*/
      String passwd="";
      /*数据库名*/
      String database = "online";  DatabaseMetaData conMD = null; 
      java.sql.Statement stmt = null;
      Connection con = null;
      ResultSet sqlRst = null;  try
      {
        Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
        con = DriverManager.getConnection(address,user,passwd);    conMD = con.getMetaData();
        con.setCatalog(database);
        stmt = con.createStatement();
      }catch(Exception fs) {
        out.print("Connection ERROR</p> <br>");
      }
      out.print("Connection</p> <br>");  try
      {
        stmt=con.createStatement();
        sqlRst = stmt.executeQuery("SELECT * FROM mytable");
        out.print("stmt  OK");
      }catch(Exception  gr)
      {
        out.print("stmt  ERROR");
      }  while (sqlRst.next()) 
      { 
        out.print("<p>name :" + sqlRst.getString("name") + "</p> <br>");
        out.print("<p>old :" + sqlRst.getString("old") + "</p>");
      }
    %>