to teddy_huang:
请问如何用Properties来修改呢??谢谢!!

解决方案 »

  1.   

    你改成这样
    Properties prop = new Properties();
    prop.put(Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory");
    prop.put(Context.PROVIDER_URL, urlName);
      

  2.   

    请问这句话如何修改:
    java.naming.provider.url=localhost:1099;//在最后1099出错
      

  3.   

    to tigerbananaapple
    试了,Properties prop = new Properties();报错:
    可能缺少引用,import 语句该如何写??
    谢谢!!!
      

  4.   

    import java.util.*;
    import javax.naming.*;加上就不报错了!不过DataSource ds = (DataSource)ctx.lookup("SQLServer");报错找不到类!问楼主的报错吗?
      

  5.   

    确实如此!DataSource报错!!???
      

  6.   

    package sql_server;import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import com.borland.jbcl.layout.*;
    import java.sql.*;
    import com.borland.dx.sql.dataset.*;
    import com.borland.dx.dataset.*;
    import javax.ejb.*;
    import javax.rmi.*;
    import java.util.*;
    import javax.naming.*;
    import javax.sql.*;//import com.borland.datastore.*;
    public class Frame1 extends JFrame {
      private JPanel contentPane;
      private XYLayout xYLayout1 = new XYLayout();
      private JScrollPane jScrollPane1 = new JScrollPane();
      private JTextArea jTextArea1 = new JTextArea();
      private JButton jButton1 = new JButton();
      private JButton jButton2 = new JButton();
      private JButton jButton3 = new JButton();
      private Database database1 = new Database();  //Construct the frame
      public Frame1() {
        enableEvents(AWTEvent.WINDOW_EVENT_MASK);
        try {
          jbInit();
        }
        catch(Exception e) {
          e.printStackTrace();
        }
      }
      //Component initialization
      private void jbInit() throws Exception  {
        //setIconImage(Toolkit.getDefaultToolkit().createImage(Frame1.class.getResource("[Your Icon]")));
        contentPane = (JPanel) this.getContentPane();
        contentPane.setLayout(xYLayout1);
        this.setSize(new Dimension(400, 300));
        this.setTitle("Frame Title");
        jButton1.setText("jButton1");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
          public void actionPerformed(ActionEvent e) {
            jButton1_actionPerformed(e);
          }
        });
        jButton2.setText("jButton2");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
          public void actionPerformed(ActionEvent e) {
            jButton2_actionPerformed(e);
          }
        });
        jButton3.setText("jButton3");
        database1.setConnection(new com.borland.dx.sql.dataset.ConnectionDescriptor("jdbc:weblogic:mssqlserver4:ytdx@localhost:1433", "sa", "zw", false, "weblogic.jdbc.mssqlserver4.Driver"));
        contentPane.add(jScrollPane1,  new XYConstraints(6, 7, 306, 201));
        contentPane.add(jButton1, new XYConstraints(30, 238, -1, -1));
        contentPane.add(jButton2, new XYConstraints(117, 239, -1, -1));
        contentPane.add(jButton3, new XYConstraints(204, 239, -1, -1));
        jScrollPane1.getViewport().add(jTextArea1, null);
      }
      //Overridden so we can exit when window is closed
      protected void processWindowEvent(WindowEvent e) {
        super.processWindowEvent(e);
        if (e.getID() == WindowEvent.WINDOW_CLOSING) {
          System.exit(0);
        }
      }  void jButton1_actionPerformed(ActionEvent e) {
        try    {    Class.forName("weblogic.jdbc.mssqlserver4.Driver");    Connection con = DriverManager.getConnection("jdbc:weblogic:mssqlserver4:localhost:1433;DatabaseName=ytdx","sa","zw");//此处根据你的SQLServer帐户而定。    Statement st = con.createStatement();    ResultSet res = st.executeQuery("select * from emloyees");    String line = "";    while (res.next())    line = line + res.getString("id")+"\n";    jTextArea1.setText(line);    con.close();    }    catch (Exception ex)    {    jTextArea1.setText("error : "+ex.getMessage());    }  }  void jButton2_actionPerformed(ActionEvent e) {
       Hashtable ht = new Hashtable();    ht.put(Context.INITIAL_CONTEXT_FACTORY,"weblogic.jndi.WLInitialContextFactory");    ht.put(Context.PROVIDER_URL,"t3://localhost:7001");    try    {    Context ctx = new InitialContext(ht);    DataSource ds = (DataSource)ctx.lookup("SQLServer");    Connection con = ds.getConnection("system","12345678");//此处是WebLogic7   // 的域用户和密码    Statement st = con.createStatement();    ResultSet res = st.executeQuery("select * from emloyees");    String line = "";    while (res.next())    line = line + res.getString("id")+"\n";    jTextArea1.setText(line);    con.close();    }    catch (Exception ex)    {    jTextArea1.setText("error : "+ex.getMessage());    }  }
    }//这里的程序已经不报错了!但是执行的时候报错!!error : Unable to resolve 'SQLServer' Resolved: '' Unresolved:'SQLServer'
      

  7.   

    是一个按钮即Button2_actionPerformed(ActionEvent e)事件中!
    该如修改呢??
      

  8.   

    import javax.sql.*;缺这个包所以报错,加上就不报错了!楼主试试,看看你那里能不能取出数来!
      

  9.   

    是界面风格问题!选择contentPane的属性LAYOUT为XYlayout
      

  10.   

    呵呵,你那里能取到表里的记录吗 ??让我看看你的WEBLOGIC的缓冲池配置!!
      

  11.   

    哦!我的按钮1能取得数据,但是按钮2还不能,报错位置在:
     DataSource ds = (DataSource)ctx.lookup("SQLServer");
      

  12.   

    好的!
    package sqlserverdemo;import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import java.lang.Object.*;
    import java.sql.Connection.*;
    import javax.sql.*;
    import java.sql.*;
    import java.io.IOException;
    import java.util.Hashtable;
    import  weblogic.jndi.WLInitialContextFactory.*;
    import weblogic.jndi.WLInitialContextFactoryDelegate.*;
    import  java.util.Properties.*;
    import java.util.PropertyResourceBundle.*;
    import java.util.*;
    import javax.naming.*;
    import com.borland.jbcl.layout.*;public class Frame1 extends JFrame {
      private JPanel contentPane;
      private JScrollPane jScrollPane1 = new JScrollPane();
      private JTextArea jTextArea1 = new JTextArea();
      private JButton jButton1 = new JButton();
      private JButton jButton2 = new JButton();
      private XYLayout xYLayout1 = new XYLayout();
      private FlowLayout flowLayout1 = new FlowLayout();
      private JButton jButton3 = new JButton();  //Construct the frame
      public Frame1() {
        enableEvents(AWTEvent.WINDOW_EVENT_MASK);
        try {
          jbInit();
          jButton1.setPreferredSize(new Dimension(10,10));
           jButton2.setPreferredSize(new Dimension(10,10));
        }
        catch(Exception e) {
          e.printStackTrace();
        }
      }
      //Component initialization
      private void jbInit() throws Exception  {
        //setIconImage(Toolkit.getDefaultToolkit().createImage(Frame1.class.getResource("[Your Icon]")));
        contentPane = (JPanel) this.getContentPane();
        contentPane.setLayout(xYLayout1);
        this.setSize(new Dimension(400, 300));
        this.setTitle("Frame Title");
        jButton1.setText("按钮1");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
          public void actionPerformed(ActionEvent e) {
            jButton1_actionPerformed(e);
          }
        });
        jButton2.setText("按钮2");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
          public void actionPerformed(ActionEvent e) {
            jButton2_actionPerformed(e);
          }
        });
        contentPane.setNextFocusableComponent(jButton1);
        jButton3.setText("jButton3");
        jButton3.addActionListener(new java.awt.event.ActionListener() {
          public void actionPerformed(ActionEvent e) {
            jButton3_actionPerformed(e);
          }
        });
        contentPane.add(jTextArea1,   new XYConstraints(2, 4, 400, 64));
        contentPane.add(jScrollPane1,    new XYConstraints(14, 78, 340, 193));
        jScrollPane1.getViewport().add(jButton3, null);
      }
      //Overridden so we can exit when window is closed
      protected void processWindowEvent(WindowEvent e) {
        super.processWindowEvent(e);
        if (e.getID() == WindowEvent.WINDOW_CLOSING) {
          System.exit(0);
        }
      }  void jButton1_actionPerformed(ActionEvent e) {
        try    {      Class.forName("weblogic.jdbc.mssqlserver4.Driver");      Connection con = DriverManager.getConnection("jdbc:weblogic:mssqlserver4:northwind@localhost","sa","");//此处根据你的SQLServer帐户而定。      Statement st = con.createStatement();      ResultSet res = st.executeQuery("select * from employees");      String line = "";      while (res.next())        line = line + res.getString("title")+"\n";      jTextArea1.setText(line);      con.close();    }    catch (Exception ex)    {      jTextArea1.setText("error : "+ex.getMessage());}
      }  void jButton2_actionPerformed(ActionEvent e) {
        Hashtable ht = new Hashtable();
        Properties prop = new Properties();
        //java.naming.factory.initial=com.sun.NamingContextFactory;
        //java.naming.provider.url=localhost:7001;
        ht.put(Context.INITIAL_CONTEXT_FACTORY,"weblogic.jndi.WLInitialContextFactory");    ht.put(Context.PROVIDER_URL,"t3://localhost:7001");    try    {      Context ctx = new InitialContext(ht);      DataSource ds = (DataSource)ctx.lookup("SQLServer");      Connection con = ds.getConnection("test","test1518");//此处是WebLogic7的域用户和密码      Statement st = con.createStatement();      ResultSet res = st.executeQuery("select * from employees");      String line = "";      while (res.next())        line = line + res.getString("notes")+"\n";      jTextArea1.setText(line);      con.close();    }    catch (Exception ex)    {      jTextArea1.setText("error : "+ex.getMessage());    }  }