f*****y 发帖数: 303 | 1 【 以下文字转载自 Go 讨论区 】
【 原文由 far 所发表 】
呵呵,贝利又要说话了 :)
小组比赛已近终点,大致分析一下形势
B组弃权的太多,再加上本来就稍弱一些,形势比较简单
foolshow & hongyuan基本出线已成定局,剩下就是抢好名次淘汰赛中避开强手的问题
剩下两个名额,估计将在wwww, Saga, missbear, brake, temple中产生
相对来说,wwww & Saga的形势最好,对missbear来说,必须在第七轮战胜hongyuan
若胜,前景一片光明,若负,基本没戏了
A组形势依然一片混乱,确实是死亡之组
microbe & tonihuang基本出线已定,
剩下的两个名额,
forname, woodman, dish, tatooine, loveww, tmv, far, adamant, fool, zfc, zhouyang
理论上都有希望
forname & woodman形势最好,
dish开始两轮没来,吃了大亏,后来连战连胜,现在已经上升到第五名了
第七轮对microbe非常关键,若胜,形势大好,若败,希望渺茫
tatoo |
|
z****e 发帖数: 54598 | 2 jdbc默写估计是不太可能
估计是看关键部分能否写出来
无非这三个
class.forname
drivermanager.getconnection
con.createstatement
我当初死活不明白class.forname是做什么的
后来了解java本身的机制之后才逐渐明白 |
|
z****e 发帖数: 54598 | 3 在某些时候,尤其是早期的时候
加载类库会比较慢,所以人们希望能够通过提前加载某些类库
来优化速度,现在早就不是问题了
所以你问use case是啥
我勉强能够举一个例子
比如laod image的时候
图片比较大,加载会慢一点
所以这个时候提前forname一下,会有好处
但是如果你不用static来储存images的话
forname其实也没啥效果
现在机器性能上去之后,这些东西都是鸡累
不做也罢,至于为什么
只是历史某一个阶段出现的现在不再需要的特殊优化手段罢了
就像web server上的c++一样 |
|
q*********u 发帖数: 280 | 4 java中实现的singleton一个标准模板之一阿,
比如Class.forName(com.mysql.jdbc.Driver); |
|
S*******C 发帖数: 822 | 5 package com.cdd.jdbc;
import java.sql.*;
public class CreateConnection {
public Connection conn=null;
public ResultSet rs=null;
public Statement stmt=null;
public CreateConnection() { //构造方法
}
//获取数据库连接方法
public Connection getConnection() {
try {
Class.forName("com.mysql.jdbc.Driver");
conn=DriverManager.getConnection("jdbc:mysql://mydbinstance.XXXXXXX.
us-east-1.rds.amazonaws.com:3306/db_database05","root","11111");
//不管用上... 阅读全帖 |
|
S*******C 发帖数: 822 | 6 AWS建议现在本地测试运行成功后再发布到AWS提供的服务器
http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/create_de
我的java web demo本地连接AWS提供的MySQL远端服务器运行成功(下面图片是在本地
Eclipse Tomcat中测试成功的页面),
代码如下
Class.forName("com.mysql.jdbc.Driver");
conn=DriverManager.getConnection("jdbc:mysql://mydbinstance.XXXXXXX.
us-east-1.rds.amazonaws.com:3306/db_database05","root","11111");
但我把这个demo部署到AWS的LINUX服务器运行却一直失败。我的demo只有在不含数据库
连接时才能在AWS的LINUX服务器上正常运行。
这是怎么回事?我还要做什么配置才能确保部署demo后仍然能够访问mysql数据库?跪
谢! |
|
z****e 发帖数: 54598 | 7 jdbc那行class.forname可以搞死一堆人
run |
|
z****e 发帖数: 54598 | 8
好处是便于扩展啊
比如你有n个类了
你想新增一个
用Class.forName("MyClassName"+i).newInstance();
比如你新增了一个
3
那么新建一个MyClassName3类,然后就可以开始写了
不需要修改原来代码,自己定义好interface就是了
连switch还有map都不用 |
|
t****a 发帖数: 554 | 9 继上一场south(w) < foolshow(B)
Group A Group B
tonihuang hongyuan
microbe foolshow
forname
xiliang
下一场
xiliang(B) vs. foolshow(W) |
|
f*****y 发帖数: 303 | 10 【 以下文字转载自 Go 讨论区 】
【 原文由 fool 所发表 】
发信人: casino (赌场), 信区: MIT
标 题: 赌局2-谁是大英雄?-围棋锦标赛冠军是谁?
发信站: FreeSpace (Sat Aug 5 01:27:35 2000), 站内
toni, 1:1.5
hongyuan, 1:2
forname, 1:3
mesh, 1:4
同样,每人限注100 |
|
z***h 发帖数: 7 | 11 create a table login then try this code:
import java.sql.*;
import java.io.*;
public class JdbcTest
{
public static void main(String args[])
{
//String update = "INSERT INTO login(user_name, password,
user_type) VALUES ('Guest', '143456', 'adminis')";
String query = "SELECT * FROM login";
String driver = "sun.jdbc.odbc.JdbcOdbcDriver";
String url = "jdbc:odbc:ORACLE";
String username = "scott";
String password = "tiger";
try {
// Load the driver to allow connection to the database
Class.forName( |
|
z**w 发帖数: 3 | 12 I installed Oracle 8.1.5 on my PC and got the connection problem.
I use the following code to test, the compile was fine but failed to get the
result.
import java.sql.*;
import java.math.*;
import java.io.*;
import oracle.jdbc.driver.*;
public class JDBCVersion
{
public static void main (String args []) throws SQLException,
IOException, ClassNotFoundException
{
// Load the Oracle JDBC driver
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection conn = DriverManager.getConnection
"j |
|
m*****g 发帖数: 8 | 13 Hi thanks man
That what i did, the JDBC driver standalone testing code is working well when
it called by a JAVA main file, but not when called by JSP file. The code i use
is following:
try{
Class.forName("org.gjt.mm.mysql.Driver").newInstance();
con = DriverManager.getConnection(
"jdbc:mysql://localhost/mike ?user=mike&password=mike");
System.out.println("connected to database");
} catch(ClassNotFoundException cnfe){
error="ClassNotFoundException: Could not loc |
|
B**z 发帖数: 153 | 14 it's a typical ClassNotFoundException for JDBC, it occurs at Class.forName()
check the classpath setting in your JSP environment. |
|
B**z 发帖数: 153 | 15 print out the classpaht before Class.forName()
using System.getProperty("java.class.path")
to see if the database drive class in in the classpath |
|
c********x 发帖数: 93 | 16 what's your question? if you want to load a special JDBC driver and
connect to a database, you can try like below(you need modify the driver
name and location of DB accordingly)
Class.forName("my.sql.Driver").newInstance();
Connection connect =
DriverManager.getConnection("jdbc:mysql://hostname/dbname","yourlogin","yourpa
ssword"); |
|
w********c 发帖数: 2632 | 17 Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); |
|
t********k 发帖数: 808 | 18 另外我用jdbc接连oracle,好象上面的异常是不抛出了
但还是有点问题
用下面的测试代码
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection con = DriverManager.getConnection(
"jdbcracle:thin:@localhost:1521rcl",
"scott", "tiger");
String sql = "{?=call PckgStudSltCourse.addStudPreSltCourse(?,?,?,?)}";
ResultSet rs = null;
CallableStatement cs = con.prepareCall(sql);
cs.registerOutParameter(1,java.sql.Types.INTEGER);
String [] courseIDs = {"12","34","56"};
int count = 0;
cs.setString(2,years);
cs.setString(3,termID);
cs.setStri |
|
z**h 发帖数: 85 | 19 no clue about C#, below are Java code, hope it helpful.
Connection conn=null;
Statement stat=null;
ResultSet rs=null;
try {
String server = "YourServerHostname";
String port = "5480";
String dbName = "YourDatabaseName";
String url = "jdbc:netezza://" + server + ":" + port + "/" +
dbName ;
Class.forName("org.netezza.Driver");
Properties myProp = new Properties();
myProp.put("user", ... 阅读全帖 |
|
y***e 发帖数: 39 | 20 You may have to use reflection.
An example:
import java.lang.reflect.*;
import java.io.*;
class Temp {
public Temp(String str){
System.out.println(str);}
}
public class Test{
public static void main(String[] args){
String arg=new String("test");
Object[] intArgs=new Object[]{arg};
String classname = "Temp";
try{
Class a = Class.forName(classname);
Constructor b = a.getConstructor(new Class[]{String.class});
Temp temp=(Temp)b.newInstance(intArgs);
}catch(Exception e){
}
}
} |
|
o****h 发帖数: 58 | 21
//要求做成一个method, 于是,偶这样
class Collie extends Dog{
public boolean isa(String className){ //需要全路径,如java.lang.Object
Collie param=new Collie();
try {
Class SomeClass = Class.forName(className);
// System.out.println(SomeClass);
Object obj = SomeClass.newInstance();
obj=(SomeClass)param; // 这里总是有问题呢,该怎么办 ???
return true;}
catch(Exception e){return false;}
}
}
另外一种方法倒是没问题,并且不必输入全路径,但好像烦了很多
class Collie extends Dog{
public boolean isa(String className){
|
|
m******t 发帖数: 2416 | 22
No, javac recursively checks dependency hierarchies. You can use -verbose
to see this.
One thing to be noted is whether a class is imported doesn't determine
if it's going to be rebuit along the way. It is the actual reference
actioins such as method calls that would trigger a rebuild. And if you
don't directly refer a class, it won't be rebuilt either. e.g.,
if you use Class.forName( "Class1" ), and that's the only point you would
refer to Class1, Class1.java won't be rebuilt even if it's |
|
P****e 发帖数: 385 | 23 想通过JDBC访问JBuilder的DataStore,但是在执行如下语句时
Class.forName(com.borland.jdbc.datastore)
报错:
ClassNotFoundException: com.borland.jdbc.datastore
请问问题出在哪里?我已经检查了Tools->Library,/opt/JBuilder/jds.jar已经被包括
在library里了。多谢。 |
|
c*****n 发帖数: 1 | 24 import java.sql.*;
public class MakingTheConnection {
public static void main(String[] args) {
try {
Class.forName("COM.cloudscape.core.JDBCDriver");
String sourceURL = "jdbc:cloudscape:C:/Music";
Connection databaseConnection =
DriverManager.getConnection(sourceURL);
System.out.println("Connection established successfully!");
databaseConnection.close();
}
catch (ClassNotFoundException cnfe) {
System.err.println(cnfe);
}
catch (SQLException sqle) {
System.err.println(sqle);
}
}
}
就这么一个小程序,我在clas |
|
k*****c 发帖数: 6 | 25 现在有一个类的.class文件,想获得这个类定义的public methods。
使用下面的方法来做。但对于某些类,在运行到theClass.getMethods()时就出ClassNotF
oundException(而且不能被我程序的异常处理捕获,直接退出到命令行),因为那个类引
用了一些在我的机器上没有的类。
//Class theClass=classLoader.loadClass(sClassName);
Class theClass=Class.forName(sClassName,false,classLoader);
allMethods=theClass.getMethods();
我的目的是只想得到这个类定义的所有公开功能,并不是要使用这个类。
(当然可以用decompiler去看,但我要处理大量的类,想通过程序做)
应该有办法获得吧,就象IDE可以列出类的所有功能。
请指教。谢谢! |
|
t********k 发帖数: 808 | 26 很简单的程序
编译通过
但运行时说Exception in PTPSender:java.lang.ClassNotFoundException:
COM.cloudscape.core.JDBCDriver
String sDBDriver = "COM.cloudscape.core.JDBCDriver";
String sConnURL = "jdbc:cloudscape:SimpleDB;create=true";
Class.forName(sDBDriver);
con = DriverManager.getConnection(sConnURL);
上面有什么错?
就在Sun的Jdk1.3.1,J2EE1.3.1环境
系统是win2000
谢谢!!! |
|
B******N 发帖数: 445 | 27 first:pay attention that rs.getInt(column_number), the column_number is one
based not zero based.
second:
replace:
DriverManager.registerDriver(new SQLServerDriver());
Connection conn = DriverManager.createConnection(sql, "sa", "sa");
with this:
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
Connection conn = DriverManager.getConnection(sql, "sa", "sa"); |
|
d*r 发帖数: 238 | 28 Thank you. Problem solved.
BTW, what's the difference between
DriverManager.registerDriver() and Class.forName()
null. |
|
s*********n 发帖数: 38 | 29 I have a class A, which calls class B.
If I put A in web-inf/, and B in shared/, it will work well.
But now I put A in shared/, and B in web-inf, it doesn't work and give me an
"ClassNotFoundException".
The way A call B is like this:
Class A{
...
Class clas = Class.forName(B);
record = (Record)clas.newInstance();
...
}
How can I solve this problem? I do want to keep the class A in shared/.
Thanks! |
|
s*********n 发帖数: 38 | 30 I read the java doc, and found that there is another method:
public static Class forName(String name,
boolean initialize,
ClassLoader loader)
throws ClassNotFoundException
I guess the problem is that in Tomcat, the web-inf\ and shared\ are using
different classloaders. What I have done above, by default, uses the
classloader of "shared", so that it could not find the class in "web-inf".
I am looking for the way to obtai |
|
s*********n 发帖数: 38 | 31 I have found the solution.
FYI:
use Thread.currentThread().getContextClassLoader() to obtain the classloader
of "web app". Then use this classloader to invoke Class.forName(B, true,
contextClassloader).
done.
but I am still thinking about my another proposal: instruct the "system"
classloader to load classes on the CLASSPATH.
any idea?
an |
|
qm 发帖数: 27 | 32 no, i'm not talking about the definition. what i'm saying is,
even if all methods are 'synchronized', they're still not completely
synchronized. to synchronize access to static data member, the instance method
must do something like this,
class Synchronized {
synchronized void f () {
...
synchronized ( Class.ForName("Synchronized") ) {
// acess static data member
}
// or, call synchronized static method
// to guarantee synchronization,
// you must *not* access static data membe |
|
xt 发帖数: 17532 | 33
method
Again, the code above is very interesting! :-)
So why don't you use sth like "static synchronized void f()"?
Also your synchronized( Class.forName...) is very funny.
Since you are already in class "Sinchronized", why do you
want to go through a complete dynamic symbol lookup for
the class? Just say synchronized( Synchronized.class) and it
is done. Of course I am not insane enough to synchronize my
variables to a class object so far. |
|
m******t 发帖数: 2416 | 34 In 8.4.3.6, Class.ForName is used within a static method, which is
the only way to get a class object in a static context. Your example
is different.
I wouldn't exactly call that "copy". 8-) |
|
g******a 发帖数: 730 | 35 I downloaded a tool in a pre-built version named piccolox.jar, then when I did:
java -jar piccolox.jar
I got:
java.lang.ClassNotFoundException:
at java.lang.Class.forName(Class.java:33)
at kaffe.jar.ExecJarName.main(ExecJarName.java:58)
at kaffe.jar.ExecJar.main(ExecJar.java:61)
In the same directory where piccolox.jar resides in, there is a subdirectory
named lib. lib contains ant.jar junit.jar swt-win32-2047.dll swt.jar .
My question is: Why I got this error msg? How |
|
c*****s 发帖数: 214 | 36 非也。
可以做个小试验。在Class.forName里设个断点
ClassA myClass = null;
System.out.println(ClassA.class);
你会发现ClassA在第二行被加载。
另一个方法是在ClassA里加个static块,看看什么时候执行。 |
|
n*******d 发帖数: 4 | 37 折腾了二个星期了 :(
Tomcat 4.0 on Linux, trying to connect to MySQL
It can't find the data source I defined and throws this error:
javax.servlet.ServletException: Cannot create resource instance
I'm not sure if there's any security setting preventig this?
I can access MySQL using the following jsp code:
Class.forName("org.gjt.mm.mysql.Driver");
Connection dbcon = DriverManager.getConnection(loginUrl,
loginUser, loginPasswd);
Statement statement = dbcon.createSta |
|
t********k 发帖数: 808 | 38 另外我用jdbc接连oracle,好象上面的异常是不抛出了
但还是有点问题
用下面的测试代码
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection con = DriverManager.getConnection(
"jdbcracle:thin:@localhost:1521rcl",
"scott", "tiger");
String sql = "{?=call PckgStudSltCourse.addStudPreSltCourse(?,?,?,?)}";
ResultSet rs = null;
CallableStatement cs = con.prepareCall(sql);
cs.registerOutParameter(1,java.sql.Types.INTEGER);
String [] courseIDs = {"12","34","56"};
int count = 0;
cs.setString(2,years);
cs.setString(3,termID);
cs.setStri |
|
p***p 发帖数: 559 | 39 http://blog.tomxp.com/view/186.html
Java基础方面:
1,作用域public,protected,private,以及不写时的区别
2,ArrayList和Vector的区别,HashMap和Hashtable的区别
3,char型变量能不能定义为一个中文?为什么?
4,多线程有几种表示方法,都是什么?同步有几种实现方法,都是什么?
5,继承时候类的执行顺序问题,一般都是选择题,问你将会打印出什么?
6,内部类的实现方式?
7,垃圾回收机制,如何优化程序?
8,float型float f=3.4是否正确?
Jsp方面
1,jsp有哪些内置对象?作用分别是什么?
2,jsp有哪些动作?作用分别是什么?
3,include的两种实现方式的区别?
4,两种跳转方式分别是什么?有什么区别?
Servlet方面
1,说一说Servlet的生命周期?
2,Servlet版本间(忘了问的是哪两个版本了)的不同?
Jdbc,Jdo方面
1,可能会让你写一段Jdbc连Oracle的程序.
2,Class.forName的作用?为什么要用?
3,Jdo是什么?
Xml |
|
c****r 发帖数: 185 | 40 Class.forName("...").newInstance()
实 |
|
l********r 发帖数: 187 | 41 I am always getting a "Exception: No suitable driver found for jdbc:mysql://
localhost:3306/test" from the following program. I have installed mysql
connector for Java and ODBC driver. Could anyone tell me what might be wrong
? I am using Fedora Linux 6.. The source code is listed bewlow:
import java.sql.*;
public class DBJava {
public static void main(String args[]) {
Connection con = null;
String query = "SELECT * FROM temp";
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriv |
|
r*****l 发帖数: 2859 | 42 Class.forName(), Class.newInstance()等有效reflection methods。
gui |
|
R******k 发帖数: 3942 | 43 public class DAOFactory{
String className = Properites.get("className");
Object obj = class.forName(className).newInstance();
} |
|
g*****g 发帖数: 34805 | 44 Think of Spring IoC declared in XML.
You declare a class name, a method name, and you can invoke the method.
Something like
Class> c = Class.forName(yourClassName);
Object o = c.newInstance();
Method method = c.getDeclaredMethod(yourMethod);
method.invoke(o);
You probably want to have a constructor passing in a String parameter,
something we've seen in spring IoC too.
I believe OP's problem can be resolved in a similar way, although he
may need to format his string in DB with more type details |
|
m*****k 发帖数: 731 | 45 【 以下文字转载自 Working 讨论区 】
发信人: madmonk (madmonk), 信区: Working
标 题: 你们的应用是如何存储数据库密码的
发信站: BBS 未名空间站 (Fri Sep 4 09:58:56 2009, 美东)
你们的应用是如何存储数据库密码的。不会是像如下hardcode在程序里吧?
Class.forName(“oracle.jdbc.driver.OracleDriver”);
String url = jdbc:oracle:thin:@hostname:1526:myDB;
Connection myConnection = DriverManager.getConnection(url, “username”, “
password”); |
|
F****n 发帖数: 3271 | 46 Sorry that's my mistake.
static initializer is called when a class is loaded. That's why in case such
as JDBC, simply call
Class.forName("driverClassName")
can register the driver to DriverManager. They put driver registration code
in static initializer. |
|
r*****l 发帖数: 2859 | 47 define a class, something like this:
public class FinalUTF8CharSet {
private CharSet charSet = null;
private FinalUTF8CharSet _instance = null;
private FinalUTF8CharSet() {
try {
charSet = CharSet.forName("UTF-8");
} catch (Exception e) {
// leave charSet as null
}
}
public static FinalUTF8CharSet getInstance() {
if (_instance == null) {
_instance = new FinalUTF8CharSet();
}
return _instance; |
|
h*****0 发帖数: 4889 | 48 多谢多谢。
我自己的办法是把原来的代码稍改一下
static {
Charset utf = null;
try {
utf = Charset.forName("UTF-8");
} catch (Exception e) {
//maybe add throw a runtime exception to let program die now
}
UTF = utf;
}
这样不管是编译器还是我都高兴了。 |
|
s*****i 发帖数: 355 | 49 关于java reflection的
Suppose class ClassName immplements runnable interface. Write a function
which returns a thread that attached with this class, taking the class name
string as argument.
我这么写的:
public Thread myFunction (String s) {
Thread t=null;
try {
Object o = Class.forName(s).newInstance();
t = new Thread((Runnable)o);
}
catch(Exception e ){
|
|
w*m 发帖数: 1806 | 50 很简单,就是想测试一下jdbc conneciton
在Linux下,网上照搬一个简单的代码,然后我想用xxxxxxxx/jre/bin/java去运行
请问应该如何做?
javac Conn.java and I get Conn.class
then run Java Conn get
Exception in thread "main" java.lang.NoClassDefFoundError: Conn
at gnu.java.lang.MainThread.run(libgcj.so.7rh)
Caused by: java.lang.ClassNotFoundException: Conn not found in gnu.gcj.
runtime.SystemClassLoader{urls=[file:/apps/oracle/product/10.2.0/db_1/jdbc/
lib/], parent=gnu.gcj.runtime.ExtensionClassLoader{urls=[], parent=null}}
at java.net.URL... 阅读全帖 |
|