javaÓëSQLÊý¾Ý¿âÇŽӷ½Ê½Ò×´íÎÊÌâÓëÉè¼ÆºËÐÄ
ÎÄÕÂÔ´´£¬×ªÔØÇëÓëBlogÖ÷ÈËÁªÏµ£¬robin9257@hotmail.com
JAVAÓëSQLÇŽӵÄÓÅȱµã£º
1¡¢Óŵ㣺²»ÓÃÏÂÔØÇý¶¯³ÌÐò£¬ÔÊÐíÓÃÏàͬ´úÂë·ÃÎʲ»Í¬DBMS¡£
2¡¢È±µã£ºÐ§Âʵ͡£
¾³£³öÏֵı¨´íµã£º
1¡¢java.sql.SQLException: [Microsoft][ODBC Çý¶¯³ÌÐò¹ÜÀíÆ÷] δ·¢ÏÖÊý¾ÝÔ´Ãû³Æ²¢ÇÒδָ¶¨Ä¬ÈÏÇý¶¯³ÌÐò
ÔÒò£ºODBCûÓÐÕýÈ·Á¬½Ó
·½·¨£ºODBCÖеÄϵͳDSNÓ¦¸Ã½¨Á¢ÄãµÄÊý¾ÝÔ´£¬JAVA³ÌÐòÖÐÓÃjdbc.odbc.ODBCÊý¾ÝÔ´Ãû³Æ
2¡¢java.sql.SQLException: [Microsoft][ODBC SQL Server Driver][SQL Server]µÚ 1 ÐÐ: '*' ¸½½üÓÐÓï·¨´íÎó¡£
ÔÒò£ºSQLÓï¾äд´íÁË
·½·¨£ºSQLÖÐ×Ô¼ºÊµÑéÏ£¬È»ºó¸ÄÕý¹ýÀ´¾ÍOK
ÇŽӵĺËÐijÌÐò
import java.sql.SQLException;
import java.sql.Statement;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
public class ConectionTest {
void demo()
{
//½ÓÊÜÊý¾Ý¿â´«»ØÀ´µÄÊý¾Ý
int id;
String text;
int age;
//¿ØÖÆÊý¾Ý¿âµÄ±äÁ¿
ResultSet rs;
Connection con=null;
//Á¬½ÓODBC
String url="jdbc:odbc:Person";
try{
//Á¬½ÓÇý¶¯
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con=DriverManager.getConnection(url);
Statement stmt=con.createStatement();
//ÔÚODBCÖн¨Á¢µÄ±í£¬±íÃûΪStudent£¬ÒÔÏÂΪSQLÓï¾ä
String strSQL="Select * from Student";
rs=stmt.executeQuery(strSQL);
if(rs.next())
{
do{
id=rs.getInt(1);
System.out.print("ID: "+id);
text=rs.getString(2);
System.out.print("ÐÕÃû: "+text);
text=rs.getString(3);
System.out.print("ÐÕÃû: "+text);
age=rs.getInt(4);
System.out.print("ÄêÁ䣺"+age);
}while(rs.next());
}
else{
System.out.
Ïà¹ØÎĵµ£º
1) ʱ¼äת»»º¯ÊýÖÐÈç¹ûÓÐʱ¼ä±äÁ¿yyyy-mm-ddÁ½±ßÐèÁ½''
to_date(''' || to_char(a_valid_date_end, 'yyyy-mm-dd') ||''', ''yyyy-mm-dd'')
2) select distinct(e.itemnum) bulk collect into v_itemnum
½«×Ö·û´®Êý×éÒÔ·Ö¸ô·û·Ö¸ôµÄ×Ö·û´®µ÷ÓÃ
pkg_maximo_common.get_string(v_itemnum, ',', '')
3) unionÖ»Êǽ«Á½¸ö½á¹ ......
Author : wufeng4552 Date : 2009-10-23
1¡¢ÎļþºÍÎļþ×éµÄº¬ÒåÓë¹Øϵ
ÿ¸öÊý¾Ý¿âÓÐÒ»¸öÖ÷Êý¾ÝÎļþ.ºÍÈô¸É¸ö´ÓÎÄ ......
ÏÂÔصØÖ·£º http://download.csdn.net/source/1805903
private string ReArrange(string str)
{
string[] keywords = new string[] {"select","from","where","and","order\\s+by","or","into",
"update","set","delete","haveing" ......
ÔÚSQLÓï¾äÓÅ»¯¹ý³ÌÖУ¬ÎÒÃǾ³£»áÓõ½hint,ÏÖ×ܽáÒ»ÏÂÔÚSQLÓÅ»¯¹ý³ÌÖг£¼ûOracle HINTµÄÓ÷¨£º
1. /*+ALL_ROWS*/
±íÃ÷¶ÔÓï¾ä¿éÑ¡Ôñ»ùÓÚ¿ªÏúµÄÓÅ»¯·½·¨,²¢»ñµÃ×î¼ÑÍÌÍÂÁ¿,ʹ×ÊÔ´ÏûºÄ×îС»¯.
ÀýÈç:
SELECT /*+ALL+_ROWS*/ EMP_NO,EMP_NAM,DAT_IN from BSEMPMS WHERE EMP_NO='SCOTT';
2. /*+FIRST_ROWS*/
±í ......
Êý¾Ý´¦ÀíÊǵ±Ç°Êý¾Ý¿â³£¼ûµÄÓ¦Óá£Ò»Ð©Êý¾Ý¿â×é³ÉDATA mart´ÓÊý¾ÝÔ´Àï³éÈ¡¹ØÐĵıí½øÐоۺϣ¬½«½á¹ûÍÆË͵½Ëã·¨ÖнøÐд¦Àí£¬´Ó¶ø¸ßÐÔÄܵĻشðÓû§µÄ²éѯ¡£
×ÜËùÖÜÖª£¬LogÎļþÊǼǼÊý¾Ý¿â²Ù×÷µÄÎļþ£¬¶ÔÊý¾Ý¿âµÄÍêÕûÐÔ£¬Ò»ÖÂÐÔÓÐ×ÅÖØÒªµÄÒâÒå¡£×÷ΪÊý¾Ý´¦ÀíµÄÒ»¸ö³£¼ûºó¹ûÊÇLogÎļþµÄ³¬¼¶ÅÓ´ó¡£ËäÈ»½«Êý¾Ý¿âµÄ»Ö¸´Ä£Ê½ÉèÖó ......