当前位置: 技术问答>java相关
请java的高手帮我看看这个程序。
来源: 互联网 发布时间:2015-08-01
本文导语: import java.sql.*; public class CreateCoffees { public static void main(String args[]) { String url = "jdbc:mySubprotocol:myDataSource"; Connection con; String createString; createString = "create tab...
import java.sql.*;
public class CreateCoffees {
public static void main(String args[]) {
String url = "jdbc:mySubprotocol:myDataSource";
Connection con;
String createString;
createString = "create table COFFEES "+"(COF_NAME varchar(32), " +
"SUP_ID int, " +
"PRICE float, " +"SALES int, " +
"TOTAL int)";
Statement stmt;
try {
Class.forName("myDriver.ClassName");
}
catch(java.lang.ClassNotFoundException e) {
System.err.print("ClassNotFoundException: ");
System.err.println(e.getMessage());
}
try {
con = DriverManager.getConnection(url,"myLogin", "myPassword");
stmt = con.createStatement();
stmt.executeUpdate(createString);
stmt.close();
con.close();
}
catch(SQLException ex) {
System.err.println("SQLException: " + ex.getMessage());
}
}
}
请问这是用的第几种jdbc驱动程序?
String url = "jdbc:mySubprotocol:myDataSource里面的mySubprotocol和myDataSource代表什么?
Class.forName("myDriver.ClassName");里面的myDriver.ClassName什么意思。
谢谢!
|
myDriver.ClassName是读取相应数据库内容的类
下面是一个例子
driv="org.hsqldb.jdbcDriver";
//url="jdbc:hsqldb:hello";
url="jdbc:hsqldb:hsql://localhost";
username="sa";
password="";
Class.forName(driv).newInstance();
// Class.forName 装载驱动程序
Connection con=DriverManager.getConnection(url, username, password);
下面是一个例子
driv="org.hsqldb.jdbcDriver";
//url="jdbc:hsqldb:hello";
url="jdbc:hsqldb:hsql://localhost";
username="sa";
password="";
Class.forName(driv).newInstance();
// Class.forName 装载驱动程序
Connection con=DriverManager.getConnection(url, username, password);