路过秋天

同样的3年,有的人从学生到当了MVP了,而我却在原地,卖弄当年的代码,秋天的风,有点凄,有点凉!

公告信息
内涵是很强大的~~~别看外表~~~当犀利哥入侵不了的时候,感觉有种莫名的失落~~~
文章档案
最新评论

基础却容易被忽略的那点事--web入侵方式及注意事项总结

搞了一上午,还是没有搞定,到处出错,郁闷了

我自己的工作机上转有DB2、MyEClipse、Visual Studio2010、Sql server2008

其中在MyEclipse用Java可以访问DB2,在Visual Studio2010上用C#可以访问Sql server2008

现在我有一个java程序和C#程序需要访问同一个数据库

可是问题出现了

我本来想让vs2010访问DB2,也在项目中引入了IBM.Data.DB2.dll的类库,可是在运行时却提示我“Error 3 The type or namespace name 'IBM' could not be found (are you missing a using directive or an assembly reference?) ”

代码如下:

 

 static class Program
    {
        
/// <summary>
        
/// The main entry point for the application.
        
/// </summary>
        [STAThread]
        
static void Main()
        {
            
//Application.EnableVisualStyles();
            
//Application.SetCompatibleTextRenderingDefault(false);
            
//Application.Run(new Main());
            GetDB2();
        }

        
static void GetDB2()
        {
            DB2Connection conn 
= null;
            DB2Command cmd 
= null;
            DB2DataReader reader 
= null;
            conn 
= new DB2Connection("DATABASE=CSD;SERVER=10.60.30.85:50000;UID=DB2ADMIN;PWD=IBMDB2");
            
try
            {
                conn.Open();
                cmd 
= new DB2Command("select * from TB_CANYOUNG", conn);
                reader 
= cmd.ExecuteReader();
                
while (reader.Read())
                {
                    Console.WriteLine(reader.GetString(
0+ "\t" + reader.GetString(1));
                }
            }
            
catch (Exception)
            {

                
throw;
            }
            
finally
            {
                
if (reader != null)
                    reader.Close();
                
if (conn != null)
                    conn.Close();
            }
        }
    }

 

这个不行,我就想在java中访问Sql server2008,msbase.jar、mssqlserver.jar、msutil.jar以及sqljdbc.jar四个jar包都引入了,可还是提示我:

Error Trace in getConnection() : [Microsoft][SQLServer 2000 Driver for JDBC][SQLServer]无法打开登录所请求的数据库 "t_name"。登录失败。
Error: No active Connection

 Java代码如下:

 

package DBHelper;

import java.sql.*;
import java.io.*;
import java.*;
public class Connect{
     
private java.sql.Connection  con = null;
     
private final String url = "jdbc:microsoft:sqlserver://";
     
private final String serverName= "127.0.0.1";
     
private final String portNumber = "1433";
     
private final String databaseName= "t_name";
     
private final String userName = "sa";
     
private final String password = "627525";
     
// Informs the driver to use server a side-cursor, 
     
// which permits more than one active statement 
     
// on a connection.
     private final String selectMethod = "cursor"
     
     
// Constructor
     public Connect(){}
     
     
private String getConnectionUrl(){
          
return url+serverName+":"+portNumber+";databaseName="+databaseName+";selectMethod="+selectMethod+";";
     }
     
     
private java.sql.Connection getConnection(){
          
try{
               Class.forName(
"com.microsoft.jdbc.sqlserver.SQLServerDriver"); 
               con 
= java.sql.DriverManager.getConnection(getConnectionUrl(),userName,password);
               
if(con!=null) System.out.println("Connection Successful!");
          }
catch(Exception e){
               e.printStackTrace();
               System.out.println(
"Error Trace in getConnection() : " + e.getMessage());
         }
          
return con;
      }
     
/*
   
          Display the driver properties, database details 
     
*/ 
     
public void displayDbProperties(){
          java.sql.DatabaseMetaData dm 
= null;
          java.sql.ResultSet rs 
= null;
 
try{
               con
= this.getConnection();
               
if(con!=null){
                    dm 
= con.getMetaData();
                    System.out.println(
"Driver Information");
                    System.out.println(
"\tDriver Name: "+ dm.getDriverName());
                    System.out.println(
"\tDriver Version: "+ dm.getDriverVersion ());
                    System.out.println(
"\nDatabase Information ");
                    System.out.println(
"\tDatabase Name: "+ dm.getDatabaseProductName());
                    System.out.println(
"\tDatabase Version: "+ dm.getDatabaseProductVersion());
                    System.out.println(
"Avalilable Catalogs ");
                    rs 
= dm.getCatalogs();
                    
while(rs.next()){
                         System.out.println(
"\tcatalog: "+ rs.getString(1));
                    } 
                    rs.close();
                    rs 
= null;
                    closeConnection();
               }
else System.out.println("Error: No active Connection");
          }
catch(Exception e){
               e.printStackTrace();
          }
     dm
=null;
     }     
     
     
private void closeConnection(){
          
try{
               
if(con!=null)
                    con.close();
               con
=null;
          }
catch(Exception e){
               e.printStackTrace();
          }
     }
     
public static void main(String[] args) throws Exception
       {
          Connect myDbTest 
= new Connect();
          myDbTest.displayDbProperties();
       }
}

 

 

知道的朋友,希望不吝赐教!谢谢

 

 

这个文章发到首页不太合适
想在园子里找个能提问的专区又不知道发到哪里

 

不过

如果这个问题在这里有人提供了很好的解决方案

我想对别人对自己都会有帮助

希望管理员不要删除了,拜托了

作者: RGY_LZY 发表于 2011-07-25 10:48 原文链接

秋色园是QBlog的官方站点,由路过秋天创建,基于cyqdata数据层框架开发的支持多用户、多语言、多数据库(access,mssql,oracle)、目录级url等功能强大的博客系统
新浪微博粉丝精灵,刷粉丝、刷评论、刷转发、企业商家微博营销必备工具"

2010/10/25 23:12:00 | 开发测试及演示 | |

#203游客2010/11/17 8:16:10
1�" or sleep(10)#
#202游客2010/11/17 8:16:02
1�' or sleep(10)#
#201游客2010/11/17 8:15:56
1" or sleep(10)#
#200游客2010/11/17 8:15:51
1' or sleep(10)#
#199游客2010/11/17 8:15:45
1 or sleep(10)#
#198游客2010/11/17 8:15:37
1');waitfor delay '0:0:10'--
#197游客2010/11/17 8:15:31
1);waitfor delay '0:0:10'--
#196游客2010/11/17 8:15:26
1';waitfor delay '0:0:10'--
#195游客2010/11/17 8:15:20
1;waitfor delay '0:0:10'--
#194游客2010/11/17 8:15:15
1" and sleep(10)#
#193游客2010/11/17 8:15:10
1' and sleep(10)#
#192游客2010/11/17 8:15:04
1 and sleep(10)#
#191游客2010/11/17 8:14:57
acunetix_bad_value' or 2='2
#190游客2010/11/17 8:14:34
1+31337-31337
#189游客2010/11/17 8:14:20
1' || '
#188游客2010/11/17 8:13:54
1" and "1"="1
#187游客2010/11/17 8:13:39
1' and '1'='1
#186游客2010/11/17 8:13:14
1 and 1=1
#185游客2010/11/17 8:12:59
1" and "1"="1" --
#184游客2010/11/17 8:12:39
1' and '1'='1' --
#183游客2010/11/17 8:12:16
1 and 1=1 --
#182你不认识我2010/11/17 6:34:29
-1.0
#181你不认识我2010/11/17 6:34:26
268435455
#180你不认识我2010/11/17 6:34:25
-268435455
#179你不认识我2010/11/17 6:34:23
NULL
#178你不认识我2010/11/17 6:34:23
'"\'\");|]*{
<\0>
#177你不认识我2010/11/17 6:34:21
-1.0
#176你不认识我2010/11/17 6:34:20
NULL
#175你不认识我2010/11/17 6:34:17
'"\'\");|]*{
<\0>
#174你不认识我2010/11/17 6:34:16
-268435455
#173你不认识我2010/11/17 6:34:16
268435455
#172游客2010/11/17 6:34:16
-1.0
#171游客2010/11/17 6:34:15
NULL
#170游客2010/11/17 6:34:15
'"\'\");|]*{
<\0>
#169游客2010/11/17 6:34:04
-268435455
#168游客2010/11/17 6:34:03
268435455
#167游客2010/11/17 6:34:03
-268435455
#166游客2010/11/17 6:34:02
-1.0
#165游客2010/11/17 6:34:00
NULL
#164游客2010/11/17 6:34:00
268435455
#163游客2010/11/17 6:33:59
'"\'\");|]*{
<\0>
#162游客2010/11/17 6:33:37
Set-Cookie: cookiename=cookievalue
#161你不认识我2010/11/17 6:33:36
Set-Cookie: cookiename=cookievalue
#160你不认识我2010/11/17 6:33:35
Set-Cookie: cookiename=cookievalue
#159游客2010/11/17 6:33:35
Set-Cookie: cookiename=cookievalue
#158你不认识我2010/11/17 6:33:28
^(#$!@#$)(()))******
#157你不认识我2010/11/17 6:33:28
!(()
#156游客2010/11/17 6:33:27
^(#$!@#$)(()))******
#155游客2010/11/17 6:33:22
!(()
#154你不认识我2010/11/17 6:33:20
^(#$!@#$)(()))******