请问各位, 你是不是实例化了一个抽象的方法,在main方法里面。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 就是连接数据的方法呀,代码如下,package java_jin;import java.sql.*;public class BatchUpdate {public static void main(String args[]) throws SQLException{ ResultSet rs=null; PreparedStatement ps=null; String url="jdbc:oracle:thin:@195.100.130.55:1521:ora"; Connection con; Statement stmt; //加载数据库驱动 try{ Class.forName("oracle.jdbc.driver.OracleDriver"); }catch(java.lang.ClassNotFoundException e) { System.err.print("ClassNotFound Exception:"); System.err.println(e.getMessage()); } try{ con=DriverManager.getConnection(url,"hr","hr"); //提交连接请求 con.setAutoCommit(false); stmt=con.createStatement(); stmt.addBatch("insert into table_1 values(1,'新概念1')"); stmt.addBatch("insert into table_1 values(2,'新概念2')"); stmt.addBatch("insert into table_1 values(3,'新概念3')"); int[] updateCounts=stmt.executeBatch(); con.commit(); con.setAutoCommit(true); ResultSet uprs=stmt.executeQuery("select * from table_1"); while(uprs.next()) { int id=uprs.getInt("id"); String xx=uprs.getString("name"); System.out.println(id +" "+ xx); } uprs.close(); stmt.close(); con.close(); } catch(BatchUpdateException b) { System.err.println("--BatchUpdateException---"); System.err.println("SQLState:"+b.getSQLState()); System.err.println("Message:"+b.getMessage()); System.err.println("Vendor:"+b.getErrorCode()); System.err.println("Update Counts:"); int[] updateCounts=b.getUpdateCounts(); for(int i=0;i<updateCounts[i];i++) { System.err.print(updateCounts[i]+" "); } System.err.println(" "); } catch(SQLException ex) { System.err.println("--SQLException---"); System.err.println("SQLState:"+ex.getSQLState()); System.err.println("Message:"+ex.getMessage()); System.err.println("Vendor:"+ex.getErrorCode()); } }} 如何指定弹出窗口的位置?(SWT开发) 程序有点问题,求助! 关于sjcp泛型的几个问题 使用java读取sqlserver中的text类型时出现中文乱码,请大家帮看看。谢谢。 急救,十万火急! 为什么.html能打开,.jsp不能打开? 初學者有問題求教 如何用jbuilder对程序打包,知道的请告诉我,不胜感激。 怎样写一个文件控制数据库连接??在线等,解决后马上送分!! 转学Java有疑问,请问经典的入门级的Java书和精通级的书是那几本? 高分:谁能给一些用JAVA开发WEBMAIL的资料和方法? 如何将字符串转换成日期类型啊!急啊!
import java.sql.*;
public class BatchUpdate
{
public static void main(String args[]) throws SQLException
{
ResultSet rs=null;
PreparedStatement ps=null;
String url="jdbc:oracle:thin:@195.100.130.55:1521:ora";
Connection con;
Statement stmt;
//加载数据库驱动
try{
Class.forName("oracle.jdbc.driver.OracleDriver");
}catch(java.lang.ClassNotFoundException e)
{
System.err.print("ClassNotFound Exception:");
System.err.println(e.getMessage());
}
try{
con=DriverManager.getConnection(url,"hr","hr");
//提交连接请求
con.setAutoCommit(false);
stmt=con.createStatement();
stmt.addBatch("insert into table_1 values(1,'新概念1')");
stmt.addBatch("insert into table_1 values(2,'新概念2')");
stmt.addBatch("insert into table_1 values(3,'新概念3')");
int[] updateCounts=stmt.executeBatch();
con.commit();
con.setAutoCommit(true);
ResultSet uprs=stmt.executeQuery("select * from table_1");
while(uprs.next())
{
int id=uprs.getInt("id");
String xx=uprs.getString("name");
System.out.println(id +" "+ xx);
}
uprs.close();
stmt.close();
con.close();
}
catch(BatchUpdateException b)
{
System.err.println("--BatchUpdateException---");
System.err.println("SQLState:"+b.getSQLState());
System.err.println("Message:"+b.getMessage());
System.err.println("Vendor:"+b.getErrorCode());
System.err.println("Update Counts:");
int[] updateCounts=b.getUpdateCounts();
for(int i=0;i<updateCounts[i];i++)
{
System.err.print(updateCounts[i]+" ");
}
System.err.println(" ");
}
catch(SQLException ex)
{
System.err.println("--SQLException---");
System.err.println("SQLState:"+ex.getSQLState());
System.err.println("Message:"+ex.getMessage());
System.err.println("Vendor:"+ex.getErrorCode());
}
}
}