借花献佛.
import java.sql.*;
public class ConnectionTest{
String driver = "oracle.jdbc.driver.OracleDriver";
String url="jdbc:oracle@thin:@****:1521:*****";
String username="zn";
String password="zn";
public String getDriver(){
return this.driver;
}
public String getUrl(){
return this.url;
}
public String getUsername(){
return this.username;
}
public String getPassword(){
return this.password;
} public static void main(String[] args){
try{
ConnectionTest ct=new ConnectionTest();
String dr=ct.getDriver();
String ul=ct.getUrl();
String user=ct.getUsername();
String pw=ct.getPassword();
Class.forName(dr);
Connection connection=DriverManager.getConnection(ul,user,pw);
System.out.println(connection.getCatalog());
connection.close();
}
catch(Exception e){
System.out.println(e);
}
}
}
你能读出数据的话,就表示成功.
import java.sql.*;
public class ConnectionTest{
String driver = "oracle.jdbc.driver.OracleDriver";
String url="jdbc:oracle@thin:@****:1521:*****";
String username="zn";
String password="zn";
public String getDriver(){
return this.driver;
}
public String getUrl(){
return this.url;
}
public String getUsername(){
return this.username;
}
public String getPassword(){
return this.password;
} public static void main(String[] args){
try{
ConnectionTest ct=new ConnectionTest();
String dr=ct.getDriver();
String ul=ct.getUrl();
String user=ct.getUsername();
String pw=ct.getPassword();
Class.forName(dr);
Connection connection=DriverManager.getConnection(ul,user,pw);
System.out.println(connection.getCatalog());
connection.close();
}
catch(Exception e){
System.out.println(e);
}
}
}
你能读出数据的话,就表示成功.
程序代码:
=================
<%@ page contentType="text/html;charset=gb2312"%>
<%@ page import="java.sql.*"%>
<html>
<body>
<%
String url="jdbc:oracle:thin:@sheng";
String user="system";
String password="manager";
try {
Class.forName("oracle.jdbc.driver.OracleDriver");
}catch( ClassNotFoundException e){
out.println(e.toString());
}
try {
Connection conn= DriverManager.getConnection(url,user,password);
Statement stmt=conn.createStatement(ResultSet.
TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
String sql="select * from student";
ResultSet rs=stmt.executeQuery(sql);
while(rs.next()) {
%>
您的第一个字段内容为:<%=rs.getString(1)%>
您的第二个字段内容为:<%=rs.getString(2)%>
<% }%>
<%out.print("数据库操作成功,恭喜你");%>
<%
rs.close();
stmt.close();
conn.close();
}catch( SQLException e){
out.println(e.toString());
}
%>
</body>
</html>
"Frame1.java": Error #: 475 : class ConnectionTest is public; must be declared in a file named ConnectionTest.java at line 7, column 8指向的是public class ConnectionTest
是什么意思?
菜鸟求教,我在自己的机子上装的是jbuilder5用的是jdk1.3,在jdk1.3\jre\lib下没有ext,我把jdbc驱动classes12.zip考到jbuilder5/安装的根目录下行吗?
将驱动放到哪里无所谓,关键是要让classpath去指向
"Frame1.java": Error #: 475 : class ConnectionTest is public; must be declared in a file named ConnectionTest.java at line 7, column 8指向的是public class ConnectionTest
是什么意思?