Search code examples
sqlsql-serverc3p0

can not retrieve data from sql server


I can not retrieve data from db in sql server.

I use the c3p0 as the pool,this is the c3p0.properties:

c3p0.user=test
c3p0.password=123456
c3p0.jdbcUrl=jdbc:sqlserver://xxxxxx:1433;databaseName=TIMDB;SelectMethod=cursor
c3p0.driverClass=com.microsoft.sqlserver.jdbc.SQLServerDriver
c3p0.maxPoolSize=15
c3p0.testConnectionOnCheckin=true
c3p0.idleConnectionTestPeriod=3600

In the sql server,I have create a new user named test,and its default db is TIMDB,the server roles is public,and this is the user mapping: enter image description here

But when I start the application,I can get nothing.

From the log created by log4j,I can get the sql used to retrieve data,but if I copy the sql to the sql management stutio and create a new query,I can retrieve some data.

I wonder why?


Solution

  • It looks like a permissions problem to me. If the generated SQl runs when you use it in management studio (i.e under your user account) then you know the code is good. What access have you given the user "test" from your post I see "user mapping: enter image description here"? he will need at least db_datareader and possibly more depending on what code is generated.

    You could also try logging on to SQL Management studio under your "test" user and see if you can execute the code. That will eliminate the possibility that its something wrong with your application/network.