to teddy_huang:
请问如何用Properties来修改呢??谢谢!!
请问如何用Properties来修改呢??谢谢!!
解决方案 »
- 问大家个问题,java swing 下拉列表如何绑定数据库表的ID啊~!
- hibernate mant-to-one设置属性not-found="ignore"不能延迟加载如何解决?
- 关于jstl的问题 高手进啊
- Struts2文件动态下载
- struts2.1.6中的类型转换问题
- ~~~~~高分,ibatis如何动态加载数据源~~~~~~
- [hibernate的问题]一个ORM问题.最基本的,如何实现两个模型类的一对多/多对一映射.
- 还是昨天的问题,编译一个STRUTS的类,提示找不到org.apache.struts.action.*,帮帮忙,郁闷了一天了!!
- 用JBuilder9生成的Struts的war文件应该放到Tomcat的哪个目录下面?
- 高手请进:关于jtree
- 怎样用jbuilder8写jsp
- 急问:jbuilder 8中怎样发布web service,谢谢!
Properties prop = new Properties();
prop.put(Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory");
prop.put(Context.PROVIDER_URL, urlName);
java.naming.provider.url=localhost:1099;//在最后1099出错
试了,Properties prop = new Properties();报错:
可能缺少引用,import 语句该如何写??
谢谢!!!
import javax.naming.*;加上就不报错了!不过DataSource ds = (DataSource)ctx.lookup("SQLServer");报错找不到类!问楼主的报错吗?
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'
该如修改呢??
DataSource ds = (DataSource)ctx.lookup("SQLServer");
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()); } }