日期:2014-05-20  浏览次数:20843 次

JDBC两个问题
1.public   class   Function   {
public   void   createTable(Connection   con){
try   {
System.out.println( "开始创建表 ");
Statement   stm=con.createStatement();
stm.executeUpdate( "create   table   student(sid   number(6)   primary   key,sname   varchar2(10),agender   varchar2(10),sdept   varchar2(30)); ");
System.out.println( "表创建 ");
}   catch   (SQLException   e)   {
e.printStackTrace();
}
在sql语句中多一个;会报出错误
java.sql.SQLException:   ORA-00911:   invalid   character

------解决方案--------------------
貌似你那个分号是中文输入法的
用英文输入法的试试
------解决方案--------------------
(10),agender varchar2(10),sdept varchar2(30)); ");


和别的分号一比就可以看出来那个分号是中文的(全角)
------解决方案--------------------
不用分号,
------解决方案--------------------
确实不用分号也行
------解决方案--------------------
stm.executeUpdate( "create table student(sid number(6) primary key,sname varchar2(10),agender varchar2(10),sdept varchar2(30)) ");
这样应该就行了

------解决方案--------------------
大家好哦!楼主的JDBC的创建表1完整般的饿代码有人帮我做下哈!
我的邮箱:wanghuipeng1027@126.com
有酬谢的!本人感激不尽!一定会发帖表表的!
------解决方案--------------------
先建立一个连接类
import java.io.*;
import java.util.*;
import java.sql.*;

public class dbPool{
private static dbPool instance = null;

//取得连接
public static synchronized Connection getConnection() {
if (instance == null){
instance = new dbPool();
}
return instance._getConnection();
}

private dbPool(){
super();
}

private Connection _getConnection(){
try{
String sDBDriver = null;
String sConnection = null;
String sUser = null;
String sPassword = null;

Properties p = new Properties();
InputStream is = getClass().getResourceAsStream("/db.properties");
p.load(is);
sDBDriver = p.getProperty("DBDriver",sDBDriver);
sConnection = p.getProperty("Connection",sConnection);
sUser = p.getProperty("User","");
sPassword = p.getProperty("Password","");

Properties pr = new Properties();
pr.put("user",sUser);
pr.put("password",sPassword);
pr.put("characterEncoding", "GB2312");
pr.put("useUnicode", "TRUE");

Class.forName(sDBDriver).newInstance();
return DriverManager.getConnection(sConnection,pr);
}
catch(Exception se){
System.out.println(se);
return null;
}
}

//释放资源
public static void dbClose(Connection conn,PreparedStatement ps,ResultSet rs)
throws SQLException
{
rs.close();
ps.close();
conn.close();

}
}



调用连接类,实现连接:
import java.sql.*;
import java.util.*;

public class loginHandler {
public loginHandler() {
}

Connection conn;