当前位置: 技术问答>java相关
请教各位高手一个菜鸟问题
来源: 互联网 发布时间:2015-06-28
本文导语: 怎么用JAVA 编写一个与数据库连接的程序 要求:1.基本步骤正确 2.操作语句顺序正确 3.能向数据库发送SQL语句 附: 数据库源名为test 拜托各位了!! | import java.sql....
怎么用JAVA 编写一个与数据库连接的程序
要求:1.基本步骤正确
2.操作语句顺序正确
3.能向数据库发送SQL语句
附: 数据库源名为test
拜托各位了!!
要求:1.基本步骤正确
2.操作语句顺序正确
3.能向数据库发送SQL语句
附: 数据库源名为test
拜托各位了!!
|
import java.sql.*;
public class DBOperation
{
static String dataBase="jdbc:odbc:test";
public static void main (String[] args)
{
/*String createTable="create table COFFEE"+
"(COF_NAME VARCHAR(32), "+
"SUPERID INTEGER, "+
"PRICE FLOAT, "+
"SALES INTEGER, "+
"TOTAL INTEGER)";*/
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
} catch(java.lang.ClassNotFoundException e) {
System.out.println("Error:.."+e.toString());
}
try {
Connection con=DriverManager.getConnection(dataBase);
Statement stmt=con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
//stmt.executeUpdate("update coffee set sales=75 where cof_name='Colombian'");
//PreparedStatement statement=con.prepareStatement("UPDATE COFFEE SET SALES=? WHERE COF_NAME=?");
//statement.executeUpdate();
//statement.setInt(1,6);
//statement.setString(2,"'Colombian'");
//int n=statement.executeUpdate();
ResultSet rst=stmt.executeQuery("select sales from coffee");
rst.absolute(3);
rst.updateInt("sales",50);
rst.updateRow();
//System.out.println("The volumn is: "+n);
System.out.println("The new sales is: "+rst.getInt("SALES"));
stmt.close();
//statement.close();
con.close();
} catch(SQLException ex) {
System.out.println("SQLException: "+ex.toString());
System.out.println("SQLException: "+ex.getSQLState());
}
}
}
public class DBOperation
{
static String dataBase="jdbc:odbc:test";
public static void main (String[] args)
{
/*String createTable="create table COFFEE"+
"(COF_NAME VARCHAR(32), "+
"SUPERID INTEGER, "+
"PRICE FLOAT, "+
"SALES INTEGER, "+
"TOTAL INTEGER)";*/
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
} catch(java.lang.ClassNotFoundException e) {
System.out.println("Error:.."+e.toString());
}
try {
Connection con=DriverManager.getConnection(dataBase);
Statement stmt=con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
//stmt.executeUpdate("update coffee set sales=75 where cof_name='Colombian'");
//PreparedStatement statement=con.prepareStatement("UPDATE COFFEE SET SALES=? WHERE COF_NAME=?");
//statement.executeUpdate();
//statement.setInt(1,6);
//statement.setString(2,"'Colombian'");
//int n=statement.executeUpdate();
ResultSet rst=stmt.executeQuery("select sales from coffee");
rst.absolute(3);
rst.updateInt("sales",50);
rst.updateRow();
//System.out.println("The volumn is: "+n);
System.out.println("The new sales is: "+rst.getInt("SALES"));
stmt.close();
//statement.close();
con.close();
} catch(SQLException ex) {
System.out.println("SQLException: "+ex.toString());
System.out.println("SQLException: "+ex.getSQLState());
}
}
}
|
随便一本介绍java的书都有啊
|
没见过懒到这种程度。
|
郁闷!!!!!!!!!!
|
这种懒人没什么必要理他!
|
faint,我再懒一点,如何打印一个字符串?可笑!