当前位置: 技术问答>java相关
帮我看一下程序?
来源: 互联网 发布时间:2015-07-15
本文导语: import java.sql.*; public class CreateCoffees { public static void main(String args[]) { //String url = "jdbc:oracle:orcl"; String url="jdbc:oracle:thin:@188.188.188.215:orcl"; //我可以用sql plus moredev/mor...
import java.sql.*;
public class CreateCoffees {
public static void main(String args[]) {
//String url = "jdbc:oracle:orcl";
String url="jdbc:oracle:thin:@188.188.188.215:orcl";
//我可以用sql plus moredev/moredev@orcl连上数据库 。
//主机ip 188.188.188.215
Connection con;
String createString;
createString = "create table COFFEES " +
"(COF_NAME VARCHAR(32), " +
"SUP_ID INTEGER, " +
"PRICE FLOAT, " +
"SALES INTEGER, " +
"TOTAL INTEGER)";
Statement stmt;
try {
Class.forName("oracle.jdbc.driver.OracleDriver");
} catch(java.lang.ClassNotFoundException e) {
System.err.print("ClassNotFoundException: ");
System.err.println(e.getMessage());
}
try {
con = DriverManager.getConnection(url, "coredev", "coredev");
stmt = con.createStatement();
stmt.executeUpdate(createString);
stmt.close();
con.close();
} catch(SQLException ex) {
System.err.println("SQLException: " + ex.getMessage());
}
}
}
那里错了,它报告
no suitable driver,我已经设置了驱动为classpath=d:javalibclasses12.zip
public class CreateCoffees {
public static void main(String args[]) {
//String url = "jdbc:oracle:orcl";
String url="jdbc:oracle:thin:@188.188.188.215:orcl";
//我可以用sql plus moredev/moredev@orcl连上数据库 。
//主机ip 188.188.188.215
Connection con;
String createString;
createString = "create table COFFEES " +
"(COF_NAME VARCHAR(32), " +
"SUP_ID INTEGER, " +
"PRICE FLOAT, " +
"SALES INTEGER, " +
"TOTAL INTEGER)";
Statement stmt;
try {
Class.forName("oracle.jdbc.driver.OracleDriver");
} catch(java.lang.ClassNotFoundException e) {
System.err.print("ClassNotFoundException: ");
System.err.println(e.getMessage());
}
try {
con = DriverManager.getConnection(url, "coredev", "coredev");
stmt = con.createStatement();
stmt.executeUpdate(createString);
stmt.close();
con.close();
} catch(SQLException ex) {
System.err.println("SQLException: " + ex.getMessage());
}
}
}
那里错了,它报告
no suitable driver,我已经设置了驱动为classpath=d:javalibclasses12.zip
|
当然可以啦
可以这样写
D:>java -classpath "d:test" CreateCoffees
你仔细看看和下面这句话的区别 应该能明白
D:>java d:testCreateCoffees
可以这样写
D:>java -classpath "d:test" CreateCoffees
你仔细看看和下面这句话的区别 应该能明白
D:>java d:testCreateCoffees
您可能感兴趣的文章:
本站(WWW.)旨在分享和传播互联网科技相关的资讯和技术,将尽最大努力为读者提供更好的信息聚合和浏览方式。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。